simple python solution, linear time 97.1%


  • 0
    J
    class Solution(object):
        def findMaxConsecutiveOnes(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            max_ = 0
            count = 0
            for i in nums:
                if i == 1:
                    count += 1
                else:
                    if count > max_:
                        max_ = count
                    count = 0
            return max_ if count < max_ else count
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.