8000 * Done with "1991. Find the Middle Index in Array". · garciparedes/leetcode@be1d005 · GitHub
[go: up one dir, main page]

Skip to content

Commit be1d005

Browse files
committed
* Done with "1991. Find the Middle Index in Array".
1 parent 81ebc34 commit be1d005

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
def findMiddleIndex(self, nums: List[int]) -> int:
3+
total = sum(nums)
4+
current = 0
5+
for i in range(len(nums)):
6+
current += nums[i]
7+
if current - nums[i] == total - current:
8+
return i
9+
return -1

0 commit comments

Comments
 (0)
0