Last updated 2 years ago
class Solution: def longestOnes(self, nums: List[int], k: int) -> int: slow, fast, zeros, ans = 0, 0, 0, 0 while fast < len(nums): if nums[fast] == 0: zeros += 1 if zeros > k: if nums[slow] == 0: zeros -= 1 slow += 1 ans = max(ans, fast - slow + 1) fast += 1 return ans