classSolution:defminSubArrayLen(self,s:int,nums: List[int]) ->int: n =len(nums)if n ==0:return0 start, end =0,0 current, length =0, n +1while end < n: current += nums[end]while current >= s: length =min(length, end - start +1) current -= nums[start] start +=1 end +=1return0if length > n else length
classSolution:defminSubArrayLen(self,s:int,nums: List[int]) ->int:ifnot nums:return0 n =len(nums) ans = n +1 sums = [0]for i inrange(n): sums.append(sums[-1] + nums[i])# `sums`最终的长度为`n+1`for i inrange(n): target = s + sums[i] bound = bisect.bisect_left(sums, target)if bound !=len(sums): ans =min(ans, bound - i)return0if ans == n +1else ans