[Java/Python] Easy Understood Solution
Explanation\nCount the elements with Counter\nIf k > 0, for each element i, check if i + k exist.\nIf k == 0, for each element i, check if count[i] > 1\n\n\n# E
# **Explanation**\nCount the elements with `Counter`\nIf `k > 0`, for each element `i`, check if `i + k` exist.\nIf `k == 0`, for each element `i`, check if `count[i] > 1`\n<br>\n\n# **Explanation**\nTime `O(N)`\nSpace `O(N)`\n<br>\n\n**Python**\n```py\ndef findPairs(self, nums, k):\n        res = 0\n        c = collections.Counter(nums)\n        for i in c:\n            if k > 0 and i + k in c or k == 0 and c[i] > 1:\n                res += 1\n        return res\n```\nwhich equals to:\n```py\ndef findPairs(self, nums, k):\n        c = collections.Counter(nums)\n        return  sum(k > 0 and i + k in c or k == 0 and c[i] > 1 for i in c)\n```\n\n**Java**\nBy @blackspinner\n```java\n    public int findPairs(int[] nums, int k) {\n        Map<Integer, Integer> cnt = new HashMap<>();\n        for (int x : nums) {\n            cnt.put(x, cnt.getOrDefault(x, 0) + 1);\n        }\n        int res = 0;\n        for (int x : cnt.keySet()) {\n            if ((k > 0 && cnt.containsKey(x + k)) || (k == 0 && cnt.get(x) > 1)) {\n                res++;\n            }\n        }\n        return res;\n    }\n```
[]