Subarray Sum equals K

from collections import Counter
class Solution(object):
    def subarraySum(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: int
        """

        hashmap = Counter()
        hashmap[0] = 1
        sum = 0
        res = 0

        for num in nums:
            sum += num

            if sum - k in hashmap:
                res += hashmap[sum-k]

            hashmap[sum] += 1

        return res

results matching ""

    No results matching ""