Skip to content

Latest commit

 

History

History
40 lines (29 loc) · 662 Bytes

485._Max_Consecutive_Ones.md

File metadata and controls

40 lines (29 loc) · 662 Bytes

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)