Skip to content

Instantly share code, notes, and snippets.

@shaobin0604
Created April 19, 2012 08:46
Show Gist options
  • Select an option

  • Save shaobin0604/2419753 to your computer and use it in GitHub Desktop.

Select an option

Save shaobin0604/2419753 to your computer and use it in GitHub Desktop.
// you can also use imports, for example:
// import java.math.*;
class Solution {
public int equi ( int[] A ) {
if (A.length == 0) return -1;
long[] sum = new long[A.length];
sum[0] = A[0];
for (int i = 1; i < A.length; i++) {
sum[i] = sum[i - 1] + A[i];
}
for (int i = 0; i < A.length; i++) {
if ((sum[i] - A[i]) == sum[A.length - 1] - sum[i]) {
return i;
}
}
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment