Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def longestOnes(self, nums: List[int], k: int) -> int:
- left = 0
- right = 0
- count_zeros = 0
- max_window = 0
- while right < len(nums):
- # if encountered add the number of zeros seen
- if nums[right] == 0:
- count_zeros += 1
- # shift left untill the number of zeros <=k
- while count_zeros > k:
- if nums[left] == 0:
- count_zeros -= 1
- left += 1
- max_window = max(max_window, right - left + 1)
- right += 1
- return max_window
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement