Skip to content

Instantly share code, notes, and snippets.

@clarkdo
Created January 26, 2018 04:21
Show Gist options
  • Save clarkdo/7fea5ef4249fb3d3f74bd7c6134752f9 to your computer and use it in GitHub Desktop.
Save clarkdo/7fea5ef4249fb3d3f74bd7c6134752f9 to your computer and use it in GitHub Desktop.
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