Max Consecutive Ones II
Input:
[1,0,1,1,0]
Output:
4
Explanation:
Flip the first zero will get the the maximum number of consecutive 1s.
After flipping, the maximum number of consecutive 1s is 4.Last updated
Input:
[1,0,1,1,0]
Output:
4
Explanation:
Flip the first zero will get the the maximum number of consecutive 1s.
After flipping, the maximum number of consecutive 1s is 4.Last updated
class Solution:
def findMaxConsecutiveOnes(self, nums: List[int]) -> int:
s,e,counter, ll,maxLen=0,0,0, len(nums),0
while e < ll:
counter = counter if nums[e] == 1 else counter+1
e = e+1
while counter > 1:
counter = counter if nums[s] == 1 else counter-1
s = s+1
maxLen = max(maxLen, e - s)
return maxLen