class Solution {
public int subarraySum(int[] nums, int k) {
Map<Integer,Integer> map = new HashMap<>();
int count=0,sum=0;
map.put(0,1);
for(int i:nums){
sum += i;
if(map.containsKey(sum-k))
count += map.get(sum-k);
map.compute(sum,(key,v)->v==null ? 1 : v+1);
}
return count;
}
}