Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int findPairs(vector<int>& nums, int k) {
- unordered_map<int, int> count;
- for(int x: nums) count[x]++;
- int ans = 0;
- for(auto x: count)
- if((k>0 && count.count(x.first+k)) || (k == 0 && x.second > 1))
- ans++;
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement