和为K的子数组(medium难度)
https://leetcode-cn.com/problems/subarray-sum-equals-k/
<方法一>:枚举
public class Solution {
public int subarraySum(int[] nums, int k) {
int count = 0;
for (int start = 0; start < nums.length; ++start) {
int sum = 0;
for (int end = start; end >= 0; --end) {
sum += nums[end];
if (sum == k) {
count++;
}
}
}
return count;
}
}
作者: