1004. Max Consecutive Ones III
- if smaller than k, increase the size of the window
- once increased the size, can not decrease, since it is already the max number of ones
class Solution:
def longestOnes(self, nums: List[int], k: int) -> int:
l = 0
for r in range(len(nums)):
k -= 1 - nums[r]
if k < 0:
k += 1 - nums[l]
l += 1
return r - l + 1