Leetcode 分享筆記

485. Max Consecutive Ones

等級: Easy

原始題目連結請點此

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