Skip to content

Commit df938d5

Browse files
Create 0724. Find Pivot Index.py
1 parent 3b55af2 commit df938d5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

0724. Find Pivot Index.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#Runtime: 144 ms, faster than 87.27% of Python3 online submissions for Find Pivot Index.
2+
#Memory Usage: 15.3 MB, less than 94.14% of Python3 online submissions for Find Pivot Index.
3+
4+
class Solution:
5+
def pivotIndex(self, nums: List[int]) -> int:
6+
l = list(accumulate(nums))
7+
r = list(accumulate(nums[::-1]))
8+
r = r[::-1]
9+
for i in range(len(l)):
10+
if l[i] == r[i]:
11+
return i
12+
if sum(nums[1:]) == 0:
13+
return 0
14+
if sum(nums[:-1]) == 0:
15+
return len(nums) - 1
16+
return -1

0 commit comments

Comments
 (0)