mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
@ -181,23 +181,23 @@ class Solution:
|
|||||||
index += 1
|
index += 1
|
||||||
return 0 if res==float("inf") else res
|
return 0 if res==float("inf") else res
|
||||||
```
|
```
|
||||||
```python3
|
```python
|
||||||
#滑动窗口
|
# 滑动窗口
|
||||||
class Solution:
|
class Solution:
|
||||||
def minSubArrayLen(self, target: int, nums: List[int]) -> int:
|
def minSubArrayLen(self, target: int, nums: List[int]) -> int:
|
||||||
if nums is None or len(nums)==0:
|
if nums is None or len(nums) == 0:
|
||||||
return 0
|
return 0
|
||||||
lenf=len(nums)+1
|
lenf = len(nums) + 1
|
||||||
total=0
|
total = 0
|
||||||
i=j=0
|
i = j = 0
|
||||||
while (j<len(nums)):
|
while (j < len(nums)):
|
||||||
total=total+nums[j]
|
total = total + nums[j]
|
||||||
j+=1
|
j += 1
|
||||||
while (total>=target):
|
while (total >= target):
|
||||||
lenf=min(lenf,j-i)
|
lenf = min(lenf, j - i)
|
||||||
total=total-nums[i]
|
total = total - nums[i]
|
||||||
i+=1
|
i += 1
|
||||||
if lenf==len(nums)+1:
|
if lenf == len(nums) + 1:
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
return lenf
|
return lenf
|
||||||
|
Reference in New Issue
Block a user