Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- knakul853
- **/
- class Solution {
- public:
- int subarraySum(vector<int>& nums, int k) {
- int cur = 0;
- int n = (int)nums.size();
- unordered_map<int, int>ump;
- int ans = 0;
- ump[0] = 1;
- for( int i=0;i<n;i++ )
- {
- cur+=nums[i];
- if(ump.count(cur - k))ans+=ump[cur-k];
- ump[cur]++;
- }
- return ans;
- }
- };
Add Comment
Please, Sign In to add comment