cpp
class Solution {
public:
int pivotIndex(vector<int>& nums) {
int len = nums.size();
int left_sum = 0;
int right_sum = 0;
for(int i = 0; i < len; i++ )
{
right_sum += nums[i];
}
for(int i = 0; i < len; i++ )
{
if(i > 0)
left_sum += nums[i - 1];
if(i < len)
right_sum -= nums[i];
if(left_sum == right_sum)
return i;
}
return -1;
}
};