MCPcopy
hub / github.com/HuberTRoy/leetCode / numSubarraysWithSum

Method numSubarraysWithSum

Array/BinarySubarraysWithSum.py:31–49  ·  view source on GitHub ↗

:type A: List[int] :type S: int :rtype: int

(self, A, S)

Source from the content-addressed store, hash-verified

29"""
30class Solution(object):
31 def numSubarraysWithSum(self, A, S):
32 """
33 :type A: List[int]
34 :type S: int
35 :rtype: int
36 """
37
38 dicts = {0:1}
39
40 pre = 0
41 result = 0
42
43 for i in A:
44 pre += i
45
46 result += dicts.get(pre-S, 0)
47 dicts[pre] = dicts.get(pre, 0) + 1
48
49 return result

Callers

nothing calls this directly

Calls 1

getMethod · 0.80

Tested by

no test coverage detected