Skip to content

Commit fe1fd76

Browse files
Create 523-Continuous-Subarray-Sum.py
1 parent e4e905b commit fe1fd76

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

python/523-Continuous-Subarray-Sum.py

+18
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+
class Solution:
5+
def checkSubarraySum(self, nums: List[int], k: int) -> bool:
6+
hashmap = {}
7+
hashmap[0]=-1
8+
summ=0
9+
for i,j in enumerate(nums):
10+
summ+=j
11+
if summ%k in hashmap.keys():
12+
if i-hashmap[summ%k]>=2:
13+
return True
14+
else:
15+
continue
16+
hashmap[summ%k]=i
17+
return False
18+

0 commit comments

Comments
 (0)