4. 485 : Max Consecutive Ones

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

 

Loading...

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

예외 처리에 주의해야겠다.

 

class Solution(object):
    def findMaxConsecutiveOnes(self, nums):
        cnt = 0
        max = 0
        
        for i in range(len(nums)):
            if nums[i] == 1:
                cnt += 1
            else:
                if max < cnt:
                    max = cnt
                cnt = 0
        
        if max < cnt:
            max = cnt
                
        return max        
        """
        :type nums: List[int]
        :rtype: int
        """

 

Posted by 공놀이나하여보세
,