Skip to content

Commit 74a99ed

Browse files
Update 209. 长度最小的子数组.md
1 parent 8e02d80 commit 74a99ed

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

Sliding Window/209. 长度最小的子数组.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,28 @@ class Solution {
6161
return res == Integer.MAX_VALUE ? 0 : res;
6262
}
6363
}
64-
```
64+
```
65+
66+
67+
68+
Go:
69+
70+
```go
71+
func minSubArrayLen(target int, nums []int) int {
72+
left, right, res, sum := 0, 0, math.MaxInt, 0
73+
for right < len(nums) {
74+
sum += nums[right]
75+
for sum >= target {
76+
res = min(res, right - left + 1)
77+
sum -= nums[left]
78+
left++
79+
}
80+
right++
81+
}
82+
if res == math.MaxInt {
83+
return 0
84+
}
85+
return res
86+
}
87+
```
88+

0 commit comments

Comments
 (0)