Skip to content

485 Max Consecutive Ones

485. Max Consecutive Ones

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

难度: Easy

思路:

一行无敌

class Solution(object):
    def findMaxConsecutiveOnes(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        return len(max(''.join(map(str, nums)).split('0')))
class Solution(object):
    def findMaxConsecutiveOnes(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        res, count = [], 0
        for x in nums:
            count = 0 if x == 0 else count + 1
            res.append(count)
        return max(res)


回到顶部