from typing import List
# 贪吃蛇-右边无脑滑动、坐边看情况收缩
class Solution:
def longestOnes(self, nums: List[int], k: int) -> int:
s = len(nums)
left = 0
count = 0
max_len = 0
for right in range(s):
if nums[right] == 0:
count += 1
while count > k:
# 结算
max_len = max(max_len, right - left)
if nums[left] == 0:
count -= 1
left += 1
max_len = max(max_len, right - left + 1)
print(max_len)
class Solution:
def max_free_memory(self, memory, cnt):
s = len(memory)
left = 0
count = 0
max_len = 0
for right in range(s):
if memory[right] == "x":
count += 1
while count > cnt:
# 结算
max_len = max(max_len, right - left)
if memory[left] == "x":
count -= 1
left += 1
max_len = max(max_len, right - left + 1)
print(max_len)