Method
subarraySum
(self, nums: List[int], k: int)
Source from the content-addressed store, hash-verified
| 1 | class Solution: |
| 2 | def subarraySum(self, nums: List[int], k: int) -> int: |
| 3 | count = 0 |
| 4 | sum = 0 |
| 5 | dic = {} |
| 6 | dic[0] = 1 |
| 7 | for i in range(len(nums)): |
| 8 | sum += nums[i] |
| 9 | if sum-k in dic: |
| 10 | count += dic[sum-k] |
| 11 | dic[sum] = dic.get(sum, 0)+1 |
| 12 | return count |
| 13 | |
| 14 | # Time Complexity : |
| 15 | # O(N) -> Where N is the size of the array and we are iterating over the array once |
Callers
nothing calls this directly
Tested by
no test coverage detected