mirror of
https://github.com/chefyuan/algorithm-base.git
synced 2025-08-07 15:52:12 +00:00
添加了python代码(数组篇)
为数组篇文件夹下的代码增加了python语言版本
This commit is contained in:
@@ -82,3 +82,27 @@ public:
|
||||
};
|
||||
```
|
||||
|
||||
Python3 Code:
|
||||
|
||||
```python
|
||||
from typing import List
|
||||
import sys
|
||||
class Solution:
|
||||
def minSubArrayLen(self, s: int, nums: List[int])->int:
|
||||
leng = len(nums)
|
||||
windowlen = sys.maxsize
|
||||
i = 0
|
||||
sum = 0
|
||||
for j in range(0, leng):
|
||||
sum += nums[j]
|
||||
while sum >= s:
|
||||
windowlen = min(windowlen, j - i + 1)
|
||||
sum -= nums[i]
|
||||
i += 1
|
||||
|
||||
if windowlen == sys.maxsize:
|
||||
return 0
|
||||
else:
|
||||
return windowlen
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user