1.和为K的子数组No.560
前缀和+枚举
public int subarraySum(int[] nums, int k) {int count =0;//满足条件的个数//计算前缀和int[] preSum = new int[nums.length+1];for(int i = 1 ; i<preSum.length;i++){preSum[i]=preSum[i-1]+nums[i-1];}//查找满足kfor(int l = 0;l<preSum.length;l++){for(int r = l+1;r<preSum.length;r++){if(preSum[r]-preSum[l]==k){count++;}}}return count;}