Skip to content

Commit a3a5064

Browse files
committed
Create 0209-minimum-size-subarray-sum.go
1 parent 59f24eb commit a3a5064

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

go/0209-minimum-size-subarray-sum.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Time: O(n)
3+
Space: O(1)
4+
*/
5+
6+
func minSubArrayLen(target int, nums []int) int {
7+
minSize := len(nums) + 1
8+
L := 0
9+
curSum := 0
10+
11+
for R := range nums {
12+
curSum += nums[R]
13+
for curSum >= target {
14+
if R+1-L < minSize {
15+
minSize = R + 1 - L
16+
}
17+
curSum -= nums[L]
18+
L += 1
19+
}
20+
}
21+
if minSize == len(nums)+1 {
22+
return 0
23+
}
24+
return minSize
25+
}

0 commit comments

Comments
 (0)