diff --git a/test010.cpp b/test010.cpp new file mode 100644 index 0000000..db70ee3 --- /dev/null +++ b/test010.cpp @@ -0,0 +1,20 @@ +class Solution { +public: + int subarraySum(vector& nums, int k) { + int n = nums.size(); + vector p(n+1, 0); + for(int i = 1; i <= n; i++){ + p[i] = p[i - 1] + nums[i - 1]; + } + int ret = 0; + unordered_map data; + for(int l = n; l; l--){ + data[p[l]]++; + int target = k + p[l-1]; + if(data.count(target)){ + ret += data[target]; + } + } + return ret; + } +}; \ No newline at end of file