<reponame>dolong2110/Algorithm-By-Problems-Python<gh_stars>0
from typing import List


def longestOnes(self, nums: List[int], k: int) -> int:
    l, r = 0, 0
    while r < len(nums):
        k -= 1 - nums[r]
        if k < 0:
            k += 1 - nums[l]
            l += 1
        r += 1

    return r - l

from typing import List


def longestOnes(self, nums: List[int], k: int) -> int:
    l, r = 0, 0
    while r < len(nums):
        k -= 1 - nums[r]
        if k < 0:
            k += 1 - nums[l]
            l += 1
        r += 1

    return r - l