MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / pivotIndex

Method pivotIndex

python/0724-find-pivot-index.py:2–11  ·  view source on GitHub ↗
(self, nums: List[int])

Source from the content-addressed store, hash-verified

1class Solution:
2 def pivotIndex(self, nums: List[int]) -> int:
3 total = sum(nums) # O(n)
4
5 leftSum = 0
6 for i in range(len(nums)):
7 rightSum = total - nums[i] - leftSum
8 if leftSum == rightSum:
9 return i
10 leftSum += nums[i]
11 return -1

Callers

nothing calls this directly

Calls 1

sumFunction · 0.50

Tested by

no test coverage detected