Skip to content

Instantly share code, notes, and snippets.

@diezguerra
Created May 5, 2011 23:25
Show Gist options
  • Save diezguerra/958186 to your computer and use it in GitHub Desktop.
Save diezguerra/958186 to your computer and use it in GitHub Desktop.
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