Untitled

Anonymous
plain_text
08/28/2023 1:37 AM
484 B
21
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 res
Editor is loading...