1991. Find the Middle Index in Array

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 1991

class Solution:
    def findMiddleIndex(self, nums: List[int]) -> int:
        left, right = 0, sum(nums)
        for i, x in enumerate(nums):
            right -= x
            if left == right:
                return i
            left += x
        return -1