Skip to content

Instantly share code, notes, and snippets.

@terracotta-ko
Created June 3, 2018 20:59
gist for leetcode 724
class Solution {
public int pivotIndex(int[] nums) {
int totalSum = 0, leftSum = 0;
for(int n : nums) {
totalSum += n;
}
for(int i = 0; i < nums.length; i++) {
if(leftSum == totalSum - leftSum - nums[i]) {
return i;
}
leftSum += nums[i];
}
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment