Guest User

Untitled

a guest
Jul 20th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. <?php
  2.  
  3. function equi ( $A ) {
  4. $count = count($A);
  5. $sum = array_sum($A) - $A[0];
  6. $i = 0;
  7. $sum_left = 0;
  8. while ($i < $count) {
  9. if ($sum_left == $sum)
  10. return $i;
  11. $sum_left += $A[$i];
  12. $sum -= $A[++$i];
  13. }
  14. return -1;
  15. }
Add Comment
Please, Sign In to add comment