| Conditions | 6 |
| Paths | 8 |
| Total Lines | 17 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 32 | public static function findDuplicate3(array $nums): int |
||
| 33 | { |
||
| 34 | if (empty($nums)) { |
||
| 35 | return 0; |
||
| 36 | } |
||
| 37 | [$low, $high] = [$nums[0], count($nums) - 1]; |
||
| 38 | while ($low < $high) { |
||
| 39 | [$cnt, $mid] = [0, $low + (int)(($high - $low) / 2)]; |
||
| 40 | foreach ($nums as $num) { |
||
| 41 | if ($num <= $mid) { |
||
| 42 | $cnt++; |
||
| 43 | } |
||
| 44 | } |
||
| 45 | $cnt <= $mid ? ($low = $mid + 1) : ($high = $mid); |
||
| 46 | } |
||
| 47 | |||
| 48 | return $low; |
||
| 49 | } |
||
| 71 |