class Solution {
public:
int subarraySum(vector<int>& nums, int k) {
unordered_map<int,int> map;
map[0] = 1;
int count = 0, pre = 0;
for(auto& x : nums){
pre += x;
if(map.find(pre-k)!=map.end()) count += map[pre-k];
map[pre]++;
}
return count;
}
};
01-18
682
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交