Skip to content

Commit cc4f691

Browse files
authored
Add files via upload (#252)
1 parent 6bb1dec commit cc4f691

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Leetcode 930 solution.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
int numSubarraysWithSum(vector<int>& nums, int goal) {
4+
unordered_map<int,int> m;
5+
m[0]=1;
6+
int ans=0,s=0;
7+
for(auto x:nums)
8+
{
9+
s+=x;
10+
if(m.find(s-goal)!=m.end())
11+
ans+=m[s-goal];
12+
m[s]++;
13+
}
14+
return ans;
15+
}
16+
};

0 commit comments

Comments
 (0)