We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 59f24eb commit a3a5064Copy full SHA for a3a5064
go/0209-minimum-size-subarray-sum.go
@@ -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