Created
January 26, 2018 04:21
-
-
Save clarkdo/7fea5ef4249fb3d3f74bd7c6134752f9 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
class Solution { | |
public int solution(int[] A) { | |
int sum = 0; | |
int diff = Integer.MAX_VALUE; | |
for (int i : A) { | |
sum += i; | |
} | |
for (int i = A.length -1; i > 0; i--) { | |
sum -= 2 * A[i]; | |
int abs = Math.abs(sum); | |
if (abs < diff) { | |
diff = abs; | |
} | |
} | |
return diff; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment