Created
May 5, 2011 23:25
-
-
Save diezguerra/958186 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int equi ( int[] arr ) { | |
long left = 0; | |
long right = 0; | |
/* sumamos todos a la izquierda */ | |
for(int i : arr) { | |
left += i; | |
} | |
/* vamos comprobando y restando a la izquierda y sumando a la dcha */ | |
for(int i=0; i < arr.length; i++) { | |
if(left-arr[i] == right) { | |
return i; | |
} | |
left -= arr[i]; | |
right += arr[i]; | |
} | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment