본문 바로가기

IT/코딩테스트

[Leetcode] 485. Max Consecutive Ones

728x90

https://leetcode.com/problems/max-consecutive-ones/

class Solution:
    def findMaxConsecutiveOnes(self, nums: List[int]) -> int:
        max_count = 0
        count = 0
        for i in nums:
            if i == 1:
                count += 1
            else:
                if count > max_count:
                    max_count = count
                count = 0
        
        return max_count if max_count > count else count
728x90