Untitled
unknown
plain_text
2 years ago
361 B
11
Indexable
#python solution
class Solution:
def subarraySum(self, nums: List[int], k: int) -> int:
dic=collections.defaultdict(lambda: 0)
res=0
tot=0
for i in nums:
tot +=i
if tot==k:
res+=1
if (tot-k) in dic:
res+=dic[tot-k]
dic[tot]+=1
return resEditor is loading...