[C++/Java/Python] Counter - O(N) - Clean & Concise
Idea\n- Build cnt is a map to map unique numbers and their counts .\n- For each b in cnt: \n\t- If k > 0 and a = b - k exists then we count (a, b) as a k-diff p
**Idea**\n- Build `cnt` is a map to map `unique numbers` and `their counts` .\n- For each `b` in `cnt`: \n\t- If `k > 0` and `a = b - k` exists then we count `(a, b)` as a `k-diff pair`.\n\t- If `k = 0` and `b` appears at least 2 times then we count`(b, b)` as a `k-diff pair`.\n\n**Complexity** \n- Time & Space: O(N)\n\n**Python**\n```python\nclass Solution(object):\n    def findPairs(self, nums, k):\n        cnt = Counter(nums)\n        ans = 0\n        for b in cnt:\n            if (k > 0 and b - k in cnt) or (k == 0 and cnt[b] >= 2):\n                ans += 1\n        return ans\n```\n\n**C++**\n```c++\nclass Solution {\npublic:\n    int findPairs(vector<int>& nums, int k) {\n        unordered_map<int, int> cnt;\n        for (int x : nums)\n            cnt[x] += 1;\n        int ans = 0;\n        for (auto [b, _] : cnt)\n            if ((k > 0 && cnt.count(b - k)) || (k == 0 && cnt[b] >= 2))\n                ans += 1;\n        return ans;\n    }\n};\n```\n\n**Java**\n```java\nclass Solution {\n    public int findPairs(int[] nums, int k) {\n        HashMap<Integer, Integer> cnt = new HashMap();\n        for (int x : nums)\n            cnt.put(x, cnt.getOrDefault(x, 0) + 1);\n        \n        int ans = 0;\n        for (int b : cnt.keySet())\n            if ((k > 0 && cnt.containsKey(b - k)) || (k == 0 && cnt.get(b) >= 2))\n                ans += 1;\n        return ans;\n    }\n}\n```
[]