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. 和相同的二元子数组
猜你喜欢
转载自www.cnblogs.com/yuhong1103/p/12804847.html
今日推荐
周排行