Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
13 lines (12 sloc) 375 Bytes
//left=0,right=total;right-sum[i],if(==),return i;left+nums[i];return -1
lass Solution(object):
def pivotIndex(self, nums):
# Time: O(n)
# Space: O(1)
left, right = 0, sum(nums)
for index, num in enumerate(nums):
right -= num
if left == right:
return index
left += num
return -1
You can’t perform that action at this time.