Max Consecutive Ones
Input:
[1,1,0,1,1,1]
Output:
3
Explanation:
The first two digits or the last three digits are consecutive 1s.
The maximum number of consecutive 1s is 3.题目大意:
解题思路:
Last updated
Input:
[1,1,0,1,1,1]
Output:
3
Explanation:
The first two digits or the last three digits are consecutive 1s.
The maximum number of consecutive 1s is 3.Last updated
class Solution(object):
def findMaxConsecutiveOnes(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
maxnumber = 0
count = 0
for i in xrange(len(nums)):
if nums[i] == 1:
count += 1
maxnumber = max(maxnumber, count)
else:
count = 0
return maxnumber