```
class Solution {
public int pivotIndex(int[] nums) {
if (nums == null || nums.length < 2) return -1;
int total = 0;
for (int num : nums) total += num;
int sum = 0;
for (int i = 0; i < nums.length; i++) {
if (total - nums[i] - sum == sum) return i;
sum += nums[i];
}
return -1;
}
}
```