| Conditions | 5 |
| Paths | 5 |
| Total Lines | 18 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 30 | public static function search2(array &$nums, int $target): int |
||
| 31 | { |
||
| 32 | if (empty($nums)) { |
||
| 33 | return -1; |
||
| 34 | } |
||
| 35 | [$left, $right] = [0, count($nums)]; |
||
| 36 | while ($left < $right) { |
||
| 37 | $mid = $left + (($right - $left) >> 1); |
||
| 38 | if ($nums[$mid] > $target) { |
||
| 39 | $right = $mid; |
||
| 40 | } elseif ($nums[$mid] < $target) { |
||
| 41 | $left = $mid + 1; |
||
| 42 | } else { |
||
| 43 | return $mid; |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | return -1; |
||
| 48 | } |
||
| 50 |