485. Max Consecutive Ones

题目地址:https://leetcode.com/problems/max-consecutive-ones/description/
大意:给定一个数组,元素都是'0'或者'1',求最大连续都是'1'的个数

思路:把数组转化成string然后用split()方法分割一下求最大的长度

# 485. Max Consecutive Ones

class Solution:
    def findMaxConsecutiveOnes(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        s = ''.join(str(i) for i in nums)
        list =  s.split('0')
        return max([len(item) for item in list])




所有题目解题方法和答案代码地址:https://github.com/fredfeng0326/LeetCode

你可能感兴趣的:(485. Max Consecutive Ones)