MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / subarraySum

Method subarraySum

python/0560-subarray-sum-equals-k.py:2–12  ·  view source on GitHub ↗
(self, nums: List[int], k: int)

Source from the content-addressed store, hash-verified

1class 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

Calls 1

getMethod · 0.45

Tested by

no test coverage detected