Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 05df5a1

Browse files
Merge pull request #4 from janeyziqinglin/janeyziqinglin-patch-4
Update 0209.长度最小的子数组python版本
2 parents e2e7e55 + b10f7ed commit 05df5a1

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
@@ -179,8 +179,27 @@ class Solution:
179179
index += 1
180180
return 0 if res==float("inf") else res
181181
```
182-
183-
182+
```python3
183+
#滑动窗口
184+
class Solution:
185+
def minSubArrayLen(self, target: int, nums: List[int]) -> int:
186+
if nums is None or len(nums)==0:
187+
return 0
188+
lenf=len(nums)+1
189+
total=0
190+
i=j=0
191+
while (j<len(nums)):
192+
total=total+nums[j]
193+
j+=1
194+
while (total>=target):
195+
lenf=min(lenf,j-i)
196+
total=total-nums[i]
197+
i+=1
198+
if lenf==len(nums)+1:
199+
return 0
200+
else:
201+
return lenf
202+
```
184203
Go:
185204
```go
186205
func minSubArrayLen(target int, nums []int) int {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /