Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solution($A) {
- $count = count($A);
- $left = 0;
- $right = 0;
- if (!$count) {
- return -1;
- }
- if ($count == 1) {
- return 0;
- }
- for ($n = 1; $n < $count; $n++) {
- $right += $A[$n];
- }
- if ($left == $right) {
- return 0;
- }
- for ($n = 1; $n < $count; $n++) {
- $left += $A[$n - 1];
- $right -= $A[$n];
- if ($left == $right) {
- return $n;
- }
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement