[C++] Simple single loop approach
\nclass Solution {\npublic:\n    int findPairs(vector<int>& nums, int k) {\n        unordered_map<int,int> freq;\n        for(int i=0;i<nums.size();i++){\n     
```\nclass Solution {\npublic:\n    int findPairs(vector<int>& nums, int k) {\n        unordered_map<int,int> freq;\n        for(int i=0;i<nums.size();i++){\n            freq[nums[i]]++;\n        }\n        int count=0;\n        if(k!=0){\n            for(auto itr:freq){\n                if(freq.find(itr.first+k)!=freq.end()){\n                    count++;\n                }\n            }\n        }\n        else{\n            for(auto itr: freq){\n                if(itr.second>1){\n                    count++;\n                }\n            }\n        }\n        return count;\n    }\n};\n```
['Hash Table', 'C', 'C++']