Created
April 19, 2012 08:46
-
-
Save shaobin0604/2419753 to your computer and use it in GitHub Desktop.
Answer for http://codility.com/test/c/demoUNSPD5-BS3/
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
| // 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