classSolution:defminSubArrayLen(self, target:int, nums: List[int])->int:
left =0# left表示滑动窗口的起始点
res =float('inf')# float('inf')表示无穷大
total =0# 记录滑动窗口中的和
length =len(nums)for right inrange(length):# right表示滑动窗口的终点
total += nums[right]while total >= target:
l = right - left +1
res =min(l, res)
total -= nums[left]
left +=1if res ==float('inf'):# 说明在遍历过程中,初始的res始终没有被替换,即nums的总和小于targetreturn0else:# res被替换了,说明有满足条件的return res