题目地址: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])
网友评论