O(n) concise solution, C++
\nclass Solution {\npublic:\n    int findPairs(vector<int>& nums, int k) {\n        if(k < 0) return 0;\n        unordered_map<int,int> m;\n        for(int i = 
```\nclass Solution {\npublic:\n    int findPairs(vector<int>& nums, int k) {\n        if(k < 0) return 0;\n        unordered_map<int,int> m;\n        for(int i = 0; i < nums.size(); ++i)\n           ++m[nums[i]];\n        int res = 0;\n        if(k != 0) {\n            for(auto it = m.begin(); it != m.end(); ++it)\n               if(m.find(it->first+k) != m.end())\n                   ++res;\n        } else {\n            for(auto it = m.begin(); it != m.end(); ++it)\n               if(it->second > 1)\n                   ++res;\n        }\n        return res;\n    }\n};\n```
['C++']