**Input:** nums = [1,1,1], k = 2
**Output:** 2
**Input:** nums = [1,2,3], k = 3
**Output:** 2
class Solution {
public int subarraySum(int[] nums, int k) {
// edge cases
if (nums == null || nums.length == 0) return 0;
int count = 0;
Map<Integer, Integer> map = new HashMap<>();
map.put(0,1); // init
int currSum = 0;
for (int i = 0; i < nums.length; i++) {
currSum += nums[i];
int oldSum = currSum - k;
count += map.getOrDefault(oldSum, 0);
map.put(currSum, map.getOrDefault(currSum, 0) + 1);
}
return count;
}
}