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

Commit0ab4587

Browse files
authored
Create 0930-binary-subarrays-with-sum.kt
1 parent579c774 commit0ab4587

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
classSolution {
2+
funnumSubarraysWithSum(nums:IntArray,goal:Int):Int {
3+
4+
funhelper(x:Int):Int {
5+
if (x<0)return0
6+
7+
var res=0
8+
var l=0
9+
var cur=0
10+
for (rin0 until nums.size) {
11+
cur+= nums[r]
12+
13+
while (cur> x)
14+
cur-= nums[l++]
15+
16+
res+= (r- l+1)
17+
}
18+
19+
return res
20+
}
21+
22+
return helper(goal)- helper(goal-1)
23+
}
24+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp