prefix sum
class Solution(object): def pivotIndex(self, nums): """ :type nums: List[int] :rtype: int """ p,size=[0],len(nums) if size==0: return -1 for val in nums: p.append(p[-1]+val) for i in range(size): if p[i+1]==p[size]-p[i]: return i return -1