485 - Max Consecutive Ones
Written on May 4, 2017
Tweet
Given a binary array, find the maximum number of consecutive 1s in this array.
class Solution(object):
def findMaxConsecutiveOnes(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
ret = count = 0
for num in nums:
if num == 0:
count = 0
else:
count += 1
ret = max(ret, count)
return ret