본문 바로가기
python-algorithm

leetcode 1991. Find the Middle Index in Array

by 무적김두칠 2022. 3. 24.

1
2
3
4
5
6
class Solution:
    def findMiddleIndex(self, nums: List[int]) -> int:
        ans=-1
        for i in rangelen(nums)):
            if sum(nums[:i])==sum(nums[i+1:]) : ans=i; break
        return ans
cs

 

반응형

댓글