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