Skip to main content

485. Max Consecutive Ones

https://leetcode.com/problems/max-consecutive-ones

Python

class Solution:
def findMaxConsecutiveOnes(self, nums: List[int]) -> int:
if not nums:
return 0

count, max_count = 0, 0
for num in nums:
if num == 1:
count += 1
else:
max_count = max(max_count, count)
count = 0

return max_count if max_count > count else count