class Solution {

public int subarraySum(int[] nums, int k) {

int[] sum = new int[nums.length + 1];

int res = 0;

sum[0] = 0;

for(int i= 0 ;i < nums.length;i++) sum[i+1] = nums[i] + sum[i];

for(int i = 0;i <= nums.length;i++) {

for(int j = 0;j <i;j++ ) {

if(sum[i] - sum[j] == k) res++;

}

}

return res;

}

}