Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita3a5064

Browse files
committed
Create 0209-minimum-size-subarray-sum.go
1 parent59f24eb commita3a5064

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
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+
funcminSubArrayLen(targetint,nums []int)int {
7+
minSize:=len(nums)+1
8+
L:=0
9+
curSum:=0
10+
11+
forR:=rangenums {
12+
curSum+=nums[R]
13+
forcurSum>=target {
14+
ifR+1-L<minSize {
15+
minSize=R+1-L
16+
}
17+
curSum-=nums[L]
18+
L+=1
19+
}
20+
}
21+
ifminSize==len(nums)+1 {
22+
return0
23+
}
24+
returnminSize
25+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp