Skip to content

Commit

Permalink
added 0560
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kathyayani125 committed Jan 6, 2023
1 parent 59f24eb commit 377a54f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cpp/0560-subarray-sum-equals-k.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution {
public:
int subarraySum(vector<int>& nums, int target) {
int i=0,j=0,count=0,n=size(nums),sum=0;
unordered_map<int,int>mp;
while(j<n){
sum+=nums[j];
if(sum==target)count++;
if(mp.find(sum-target)!=mp.end())count+=mp[sum-target];
mp[sum]++;
j++;
}
return count;
}
};

0 comments on commit 377a54f

Please sign in to comment.