class Solution { public int subarraySum(int[] nums, int k) { HashMap<Integer,Integer> h=new HashMap<>(); int sum=0; int count=0; h.put(0,1); for(int i=0;i<nums.length;i++){ sum+=nums[i]; if(h.containsKey(sum-k)){ count+=h.get(sum-k); } h.put(sum,h.getOrDefault(sum,0)+1); } return count; } }
原文地址:https://www.cnblogs.com/NeverGiveUp0/p/11443033.html
时间: 2024-11-06 03:47:48