| Conditions | 7 |
| Paths | 10 |
| Total Lines | 19 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | public static function dominantIndex(array $nums): int |
||
| 10 | { |
||
| 11 | if (empty($nums)) { |
||
| 12 | return 0; |
||
| 13 | } |
||
| 14 | [$index, $n] = [0, count($nums)]; |
||
| 15 | for ($i = 0; $i < $n; $i++) { |
||
| 16 | if ($nums[$i] > $nums[$index]) { |
||
| 17 | $index = $i; |
||
| 18 | } |
||
| 19 | } |
||
| 20 | |||
| 21 | for ($i = 0; $i < $n; $i++) { |
||
| 22 | if ($index !== $i && $nums[$index] < 2 * $nums[$i]) { |
||
| 23 | return -1; |
||
| 24 | } |
||
| 25 | } |
||
| 26 | |||
| 27 | return $index; |
||
| 28 | } |
||
| 49 |