We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents f3c7bfb + 88833cb commit b764e7fCopy full SHA for b764e7f
930. Binary Subarrays With Sum
@@ -0,0 +1,31 @@
1
+class Solution {
2
+
3
+public:
4
5
+ int numSubarraysWithSum(vector<int>& nums, int goal) {
6
7
+ unordered_map<int,int> mpp;
8
9
+ int sum = 0;
10
+ int cnt = 0;
11
12
+ for(auto i:nums)
13
+ {
14
+ sum+=i;
15
+ if(sum==goal) cnt++;
16
+ if(mpp.find(sum-goal)!=mpp.end())
17
18
19
20
+ cnt+=mpp[sum-goal];
21
22
+ }
23
+ mpp[sum]++;
24
25
26
27
+ return cnt;
28
29
30
31
+};
0 commit comments