Skip to content

Commit be59fb7

Browse files
committedAug 19, 2023
add 0209-minimum-size-subarray-sum.py
1 parent bb96527 commit be59fb7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
 
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def minSubArrayLen(self, target: int, nums: List[int]) -> int:
3+
res = float('inf')
4+
l, total = 0, 0
5+
6+
for r in range(len(nums)):
7+
total += nums[r]
8+
while total >= target:
9+
res = min(res, r - l + 1)
10+
total -= nums[l]
11+
l += 1
12+
return res if res != float('inf') else 0
13+
14+
15+
16+
17+

0 commit comments

Comments
 (0)
Please sign in to comment.