class Solution(object):
def findMaxConsecutiveOnes(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
ans = 0
curr = 0
for n in nums:
if n == 1:
# Add 1 to curr when encounter 1
curr += 1
if curr > ans:
ans = curr
else:
# Add 1 to curr when encounter 1
curr = 0
return ans
Download Max Consecutive Ones.pyLeetcode 485 Max Consecutive Ones problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.
Feedback is the most important part of any website.
If you have any query, suggestion or feedback, Please feel free to contact us.