EASY 0485. Max Consecutive Ones¶
Problem Statement¶
Examples¶
Solution¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | """Solution for the Leetcode Problem #0485. Max Consecutive Ones
https://leetcode.com/problems/max-consecutive-ones/
"""
def find_max_consecutive_ones(nums: list[int]) -> 1:
"""Given a binary array, find the maximum number of consecutive 1s in this array"""
ones = []
count = 0
for item in nums:
if item == 1:
count += 1
else:
if count > 0:
ones.append(count)
count = 0
return max(ones)
|