Skip to content

Commit b10f7ed

Browse files
Update 0209.长度最小的子数组.md
滑动窗口 version of python3 code
1 parent 87abfa1 commit b10f7ed

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

problems/0209.长度最小的子数组.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,27 @@ class Solution:
162162
index += 1
163163
return 0 if res==float("inf") else res
164164
```
165-
166-
165+
```python3
166+
#滑动窗口
167+
class Solution:
168+
def minSubArrayLen(self, target: int, nums: List[int]) -> int:
169+
if nums is None or len(nums)==0:
170+
return 0
171+
lenf=len(nums)+1
172+
total=0
173+
i=j=0
174+
while (j<len(nums)):
175+
total=total+nums[j]
176+
j+=1
177+
while (total>=target):
178+
lenf=min(lenf,j-i)
179+
total=total-nums[i]
180+
i+=1
181+
if lenf==len(nums)+1:
182+
return 0
183+
else:
184+
return lenf
185+
```
167186
Go:
168187
```go
169188
func minSubArrayLen(target int, nums []int) int {

0 commit comments

Comments
 (0)