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

Commit3fbd1f6

Browse files
authored
Create 0930-binary-subarrays-with-sum.py
1 parent0ab4587 commit3fbd1f6

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
classSolution:
2+
defnumSubarraysWithSum(self,nums:List[int],goal:int)->int:
3+
4+
defhelper(x):
5+
ifx<0:return0
6+
7+
res=0
8+
l,cur=0,0
9+
forrinrange(len(nums)):
10+
cur+=nums[r]
11+
whilecur>x:
12+
cur-=nums[l]
13+
l+=1
14+
res+= (r-l+1)
15+
returnres
16+
17+
returnhelper(goal)-helper(goal-1)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp