1-liner in Python, O(n) time
\n    def findPairs(self, nums, k):\n       return len(set(nums)&{n+k for n in nums}) if k>0 else sum(v>1 for v in collections.Counter(nums).values()) if k==0 e
```\n    def findPairs(self, nums, k):\n       return len(set(nums)&{n+k for n in nums}) if k>0 else sum(v>1 for v in collections.Counter(nums).values()) if k==0 else 0\n```\nwhich is equivalent to:\n```\n    def findPairs(self, nums, k):\n        if k>0:\n            return len(set(nums)&set(n+k for n in nums))\n        elif k==0:\n            sum(v>1 for v in collections.Counter(nums).values())\n        else:\n            return 0\n```
[]