| Conditions | 4 |
| Paths | 4 |
| Total Lines | 15 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | public static function pivotIndex(array $nums): int |
||
| 10 | { |
||
| 11 | if (empty($nums)) { |
||
| 12 | return 0; |
||
| 13 | } |
||
| 14 | [$left, $right] = [0, array_sum($nums)]; |
||
| 15 | foreach ($nums as $key => $num) { |
||
| 16 | $right -= $num; |
||
| 17 | if ($left === $right) { |
||
| 18 | return $key; |
||
| 19 | } |
||
| 20 | $left += $num; |
||
| 21 | } |
||
| 22 | |||
| 23 | return -1; |
||
| 24 | } |
||
| 60 |