Problem
Given a binary array nums, return the maximum number of consecutive 1’s in the array.
Algorithm
Just count directly
Code
class Solution:
def findMaxConsecutiveOnes(self, nums: List[int]) -> int:
maxn, cnts = 0, 0
for num in nums:
if num:
cnts += 1
else:
if maxn < cnts:
maxn = cnts
cnts = 0
if maxn < cnts:
maxn = cnts
return maxn