| Conditions | 5 |
| Paths | 5 |
| Total Lines | 19 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | public static function searchInsert(array $nums, int $target): int |
||
| 10 | { |
||
| 11 | if (empty($nums)) { |
||
| 12 | return 0; |
||
| 13 | } |
||
| 14 | [$low, $high] = [0, count($nums) - 1]; |
||
| 15 | while ($low <= $high) { |
||
| 16 | $mid = (int) (($high + $low) / 2); |
||
|
|
|||
| 17 | $mid = $low + intdiv($high - $low, 2); |
||
| 18 | if ($nums[$mid] > $target) { |
||
| 19 | $high = $mid - 1; |
||
| 20 | } elseif ($nums[$mid] < $target) { |
||
| 21 | $low = $mid + 1; |
||
| 22 | } else { |
||
| 23 | return $mid; |
||
| 24 | } |
||
| 25 | } |
||
| 26 | |||
| 27 | return $low; |
||
| 28 | } |
||
| 30 |