Digking's cave

LeetCode 리트코드 ) Max Consecutive Ones (Python) 본문

코딩테스트/알고리즘

LeetCode 리트코드 ) Max Consecutive Ones (Python)

디깅 2022. 7. 27. 14:38
728x90
class Solution:
    def findMaxConsecutiveOnes(self, nums: List[int]) -> int:
        tempnum = 0
        temlist=[]
        for i in nums:
            if(i == 1):
                tempnum += 1
            else:
                temlist.append(tempnum)
                tempnum = 0
        temlist.append(tempnum)
        return max(temlist)

문제

풀이

 

반응형