public int subarraySum(int[] nums, int k) {
int count=0;
for(int i=0;i<nums.length;i++){
int sum=nums[i];
if(sum==k){
count++;
}
for(int j=i+1;j<nums.length;j++){
sum+=nums[j];
if(sum==k) count++;
}
}
return count;
}
Basic Java solution

Nice solution, it's O(n^2) but easier to understand.
I had similar implementation:
public int subarraySum(int[] nums, int k) { int res = 0; if (nums == null  nums.length == 0) return 0; for (int i = 0; i < nums.length; i++) { int temp = k; for (int j = i; j >= 0; j) { temp = temp  nums[j]; if (temp == 0) res++; } } return res; }