We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3b55af2 commit df938d5Copy full SHA for df938d5
0724. Find Pivot Index.py
@@ -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