| Conditions | 4 |
| Paths | 4 |
| Total Lines | 16 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 22 | public static function findPeakElement2(array $nums): int |
||
| 23 | { |
||
| 24 | if (empty($nums)) { |
||
| 25 | return 0; |
||
| 26 | } |
||
| 27 | [$left, $right] = [0, count($nums) - 1]; |
||
| 28 | while ($left < $right) { |
||
| 29 | $mid = $left + (int)(($right - $left) / 2); |
||
| 30 | if ($nums[$mid] < $nums[$mid + 1]) { |
||
| 31 | $left = $mid + 1; |
||
| 32 | } else { |
||
| 33 | $right = $mid; |
||
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 37 | return $left; |
||
| 38 | } |
||
| 40 |