leetcode-209-长度最小的子数组
2020-12-13 16:22
标签:class info 最小 inf lis subarray mamicode sub solution 题目描述: 方法一:双指针 O(N) 方法二: 二分 O(NlogN)* leetcode-209-长度最小的子数组 标签:class info 最小 inf lis subarray mamicode sub solution 原文地址:https://www.cnblogs.com/oldby/p/11619393.htmlclass Solution:
def minSubArrayLen(self, s: int, nums: List[int]) -> int:
left = 0
res = float(‘inf‘)
sum = 0
for i in range(len(nums)):
sum += nums[i]
while sum >= s:
res = min(res,i-left+1)
sum -= nums[left]
left += 1
return res if res != float("inf") else 0
下一篇:重学C语言