R4-滑动窗口篇
非固定滑动窗口大小
class Solution:
def minSubArrayLen(self, target: int, nums: List[int]) -> int:
n=len(nums)
ret=n+1
sm=left=0
for right,x in enumerate(nums):
sm+=x
while sm-nums[left]>=target:
sm-=nums[left]
left+=1
if sm>=target:
ret=min(ret,right-left+1)
return ret if ret<=n else 0