C++ / Python Simple and Clean O(n) Solutions
C++:\n\nclass Solution {\npublic:\n    int findPairs(vector<int>& nums, int k) {\n        unordered_map<int, int> map;\n        for(auto num:nums)\n            
**C++:**\n```\nclass Solution {\npublic:\n    int findPairs(vector<int>& nums, int k) {\n        unordered_map<int, int> map;\n        for(auto num:nums)\n            map[num]++;\n        \n        int res = 0;\n        if (k > 0) {\n            for(auto a:map)\n                if (map.find(a.first+k) != map.end()) \n                    res++;\n        }\n        \n        else {\n            for(auto a:map)\n                if (a.second > 1)\n                    res++;\n        }\n        \n        return res;\n    }\n};\n```\n**Python:**\n```\nclass Solution:\n    def findPairs(self, nums: List[int], k: int) -> int:\n        if (k == 0):\n            return len([item for item, count in collections.Counter(nums).items() if count > 1])\n        \n        nums = set(nums)\n        res = 0\n        for n in nums:\n            res += 1 if n-k in nums else 0\n        return res\n```\n**Like it? please upvote!**
['C', 'Python']