Skip to content

Instantly share code, notes, and snippets.

@shaobin0604
Created June 14, 2012 10:07
Show Gist options
  • Select an option

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

Select an option

Save shaobin0604/2929417 to your computer and use it in GitHub Desktop.
package com.pekall.onlinetest;
public class Solution {
public int equi(int[] A) {
int i, j;
int left = 0;
int right = 0;
int length = A.length;
for (i = 1; i < length; i++) {
left += A[i - 1];
for (j = i + 1; j < length; j++) {
right += A[j];
}
if (left == right && (i + 1) < length)
return i;
}
return -1;
}
public static void main(String[] args) {
int[] test = {-7, 1, 5, 2, -4, 3, 0};
Solution solution = new Solution();
System.out.println("result of equi = " + solution.equi(test));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment