MCPcopy Index your code
hub / github.com/HuberTRoy/leetCode / subarraySum

Method subarraySum

Array/SubarraySumEqualsK.py:27–46  ·  view source on GitHub ↗

:type nums: List[int] :type k: int :rtype: int

(self, nums, k)

Source from the content-addressed store, hash-verified

25"""
26class Solution(object):
27 def subarraySum(self, nums, k):
28 """
29 :type nums: List[int]
30 :type k: int
31 :rtype: int
32 """
33 dicts = {0:1}
34
35 result = 0
36
37 pre_sum = 0
38
39 for i in nums:
40 pre_sum += i
41
42 result += dicts.get(pre_sum-k, 0)
43
44 dicts[pre_sum] = dicts.get(pre_sum, 0) + 1
45
46 return result
47

Callers

nothing calls this directly

Calls 1

getMethod · 0.80

Tested by

no test coverage detected