930. 和相同的二元子数组

Posted yuhong1103

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了930. 和相同的二元子数组相关的知识,希望对你有一定的参考价值。

 1 class Solution 
 2 {
 3 public:
 4     int numSubarraysWithSum(vector<int>& nums, int k) 
 5     {
 6         unordered_map<int,int> hash;// 和+次数
 7         hash[0] = 1;
 8 
 9         int res = 0,sum = 0;
10         for(int i = 0;i < nums.size();i ++)
11         {
12             sum += nums[i];
13             res += hash[sum - k];
14             hash[sum]++;
15         }
16 
17         return res;
18     }
19 };

 

以上是关于930. 和相同的二元子数组的主要内容,如果未能解决你的问题,请参考以下文章