Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. function solution($A) {
  2.  
  3. $n = count($A);
  4. $total = 0;
  5. $actual = 0;
  6.  
  7. if(count($A) == 0){
  8. return -1;
  9. }
  10.  
  11. for($i=0;$i<count($A);$i++){
  12. $total = $total + $A[$i];
  13. }
  14.  
  15. for($i=0;$i<count($A);$i++){
  16.  
  17.  
  18. $right = $total - $actual;
  19. $teste = $total - $actual - $A[$i];
  20.  
  21. if($teste == $actual){
  22. return $i;
  23. }
  24.  
  25.  
  26. //echo "Indice: " . $i . "||" . $A[$i] . "|| left: " . $actual . "|| right: " . $right . "|| Teste: " . $teste . "\r\n";
  27.  
  28. $actual = $actual + $A[$i];
  29.  
  30.  
  31. }
  32.  
  33. return -1;
  34.  
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement