| Conditions | 5 |
| Paths | 4 |
| Total Lines | 16 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | public static function firstBadVersion(int $m, int $n): int |
||
| 10 | { |
||
| 11 | if ($m <= 0 || $n <= 0) { |
||
| 12 | return 0; |
||
| 13 | } |
||
| 14 | [$low, $high] = [1, $m]; |
||
| 15 | while ($low <= $high) { |
||
| 16 | $mid = $low + (int)(($high - $low) / 2); |
||
| 17 | if (self::isBadVersion($mid, $n)) { |
||
| 18 | $high = $mid - 1; |
||
| 19 | } else { |
||
| 20 | $low = $mid + 1; |
||
| 21 | } |
||
| 22 | } |
||
| 23 | |||
| 24 | return $low; |
||
| 25 | } |
||
| 35 |