Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def subarraySum(self, nums: List[int], k: int) -> int:
- ht = {0:1}
- res = ps = 0
- for i in nums:
- ps += i
- res += ht.get(ps-k, 0)
- ht[ps] = ht.get(ps, 0) + 1
- return res
- #sliding window works for all positives or all negatives
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement