https://leetcode.cn/problems/find-the-middle-index-in-array/submissions/
前缀和
真妙!
public static int pivotIndex(int[] nums) {
int sum = 0;
int lSum = 0;
for (int i = 0; i < nums.length; i++) {
sum += nums[i];
}
for (int i = 0; i < nums.length; i++) {
if (lSum * 2 + nums[i] == sum)
return i;
lSum += nums[i];
}
return -1;
}