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:
- left = 0
- right = 0
- window_sum = 0
- count = 0
- while right < len(nums):
- # add the right to the window
- window_sum += nums[right]
- # shrink the window untill we have sum < k
- while window_sum > k:
- window_sum -= nums[left]
- left += 1
- # if current window has sum equal to k
- if window_sum == k:
- count += 1
- # expand the window
- right += 1
- return count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement