Skip to main content

724 - Find Pivot Index

Details

KeyValue
Linkhttps://leetcode.com/problems/find-pivot-index/
LanguagePython 3
Runtime322 ms, faster than 17.15% of Python3 online submissions for Find Pivot Index
Memory Usage15.3 MB, less than 48.80% of Python3 online submissions for Find Pivot Index
DatastructuresList[int]
AlgorithmsIterate / brute-force
ComplexityTime: O(N) Memory: O(1)

Procedure

  1. ...

Code

class Solution:
def pivotIndex(self, nums: List[int]) -> int:
left_sum, total_sum = 0, sum(nums)

for i, num in enumerate(nums):
if left_sum + num + left_sum == total_sum: return i
left_sum += num

return -1