(int[] nums, int k)
| 12 | return count; |
| 13 | }*/ |
| 14 | public int subarraySum(int[] nums, int k) { |
| 15 | int count = 0, sum = 0; |
| 16 | HashMap < Integer, Integer > map = new HashMap < > (); |
| 17 | map.put(0, 1); |
| 18 | for (int i = 0; i < nums.length; i++) { |
| 19 | sum += nums[i]; |
| 20 | // check if sum - k in hash |
| 21 | if (map.containsKey(sum - k)) |
| 22 | count += map.get(sum - k); |
| 23 | // push sum into hash |
| 24 | map.put(sum, map.getOrDefault(sum, 0) + 1); |
| 25 | } |
| 26 | return count; |
| 27 | } |
| 28 | } |
nothing calls this directly
no test coverage detected