| Total Complexity | 13 |
| Total Lines | 51 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class FindPivotIndex |
||
| 8 | { |
||
| 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 | } |
||
| 25 | |||
| 26 | public static function pivotIndex2(array $nums): int |
||
| 40 | } |
||
| 41 | |||
| 42 | public static function pivotIndex3(array $nums): int |
||
| 58 | } |
||
| 59 | } |
||
| 60 |