Skip to content

Commit 377a54f

Browse files
added 0560
1 parent 59f24eb commit 377a54f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

cpp/0560-subarray-sum-equals-k.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
int subarraySum(vector<int>& nums, int target) {
4+
int i=0,j=0,count=0,n=size(nums),sum=0;
5+
unordered_map<int,int>mp;
6+
while(j<n){
7+
sum+=nums[j];
8+
if(sum==target)count++;
9+
if(mp.find(sum-target)!=mp.end())count+=mp[sum-target];
10+
mp[sum]++;
11+
j++;
12+
}
13+
return count;
14+
}
15+
};

0 commit comments

Comments
 (0)