Created
June 14, 2012 10:07
-
-
Save shaobin0604/2929417 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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