Skip to content

Commit 9f5ed78

Browse files
authored
feat: $209 add python code
1 parent b58caf7 commit 9f5ed78

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

problems/209.minimum-size-subarray-sum.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,26 @@ If you have figured out the O(n) solution, try coding another solution of which
3131

3232
## 代码
3333

34-
- 语言支持:JS,C++
34+
- 语言支持:JS,C++,Python
35+
36+
Python Code:
37+
38+
```python
39+
40+
class Solution:
41+
def minSubArrayLen(self, s: int, nums: List[int]) -> int:
42+
l = total = 0
43+
ans = len(nums) + 1
44+
for r in range(len(nums)):
45+
total += nums[r]
46+
while total >= s:
47+
if r - l + 1 < ans:
48+
ans = r - l + 1
49+
total -= nums[l]
50+
l += 1
51+
return 0 if ans == len(nums) + 1 else ans
52+
```
53+
3554

3655
JavaScript Code:
3756

0 commit comments

Comments
 (0)