Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solution($A) {
- $n = count($A);
- $total = 0;
- $actual = 0;
- if(count($A) == 0){
- return -1;
- }
- for($i=0;$i<count($A);$i++){
- $total = $total + $A[$i];
- }
- for($i=0;$i<count($A);$i++){
- $right = $total - $actual;
- $teste = $total - $actual - $A[$i];
- if($teste == $actual){
- return $i;
- }
- //echo "Indice: " . $i . "||" . $A[$i] . "|| left: " . $actual . "|| right: " . $right . "|| Teste: " . $teste . "\r\n";
- $actual = $actual + $A[$i];
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement