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

Commitfe1fd76

Browse files
Create 523-Continuous-Subarray-Sum.py
1 parente4e905b commitfe1fd76

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

‎python/523-Continuous-Subarray-Sum.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#We are basically storing sum%k and storing it in the hashmap and checking it.
2+
#Math logic is that the overall sum will get cancelled out because of modulo
3+
4+
classSolution:
5+
defcheckSubarraySum(self,nums:List[int],k:int)->bool:
6+
hashmap= {}
7+
hashmap[0]=-1
8+
summ=0
9+
fori,jinenumerate(nums):
10+
summ+=j
11+
ifsumm%kinhashmap.keys():
12+
ifi-hashmap[summ%k]>=2:
13+
returnTrue
14+
else:
15+
continue
16+
hashmap[summ%k]=i
17+
returnFalse
18+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp