python, reasonably fast (>99.4%), short  and readable, explained, different options
Let\'s start with something easy to read:\n\n\nclass Solution:\n    def findPairs(self, nums: List[int], k: int) -> int:\n        r = 0\n        if k >= 0:\n   
Let\'s start with something easy to read:\n\n```\nclass Solution:\n    def findPairs(self, nums: List[int], k: int) -> int:\n        r = 0\n        if k >= 0:\n            c = collections.Counter(nums)\n            for i in c:\n                if (k==0 and c[i]>1) or (k!=0 and i+k in c):\n                    r += 1\n        return r\n```\n\nSo there are 3 things you need to take care of:\n\n1. The k value is the *absolute* difference, so it has to be a positive number, otherwise we return 0\n2. k==0. this is a special case. let\'s say we have [1,1,1,3,3,3,3,...] the 3x1 will produce 1 pair, 4x3 - another 1. So the logic is every non unique element adds a pair. That is a typical case where collections.Counter can be used.\n3. for all other numbers - we just need to check for every i if i+k is also present.\n\nSo now we are putting it all together.\n\nr is the return value set to 0. If k<0, we return it right away - this is the first case.\nnow we create `c = collections.Counter(nums)` and then as we go through the elements, we check for both cases: where k==0 is i is repeated or if k!=0 (we can use k>0 instead) and i+k is also in c.\n\nSo this program works just fine and it looks readable, but if you want to save a couple lines ... If you look at the main loop, it\'s a combination of a `for` and an `if` and it adds either 1 or nothing. So it could be a good case to use a comprehension instead:\n\n\n```\nclass Solution:\n    def findPairs(self, nums: List[int], k: int) -> int:\n        c = collections.Counter(nums)\n        return 0 if k<0 else sum([ 1  for i in c if (k==0 and c[i]>1) or (k!=0 and i+k in c) ])\n```\n\nThe logic is exactly the same, just different presentation.\n\nAnd if for some reason you don\'t want to use collections,  you can replace it with:\n\n```\nclass Solution:\n    def findPairs(self, nums: List[int], k: int) -> int:\n        #c = collections.Counter(nums)     \n        c={}\n        for i in nums:\n            c[i] = c.get(i, 0) + 1                \n        return 0 if k<0 else sum([ 1  for i in c if (k==0 and c[i]>1) or (k!=0 and i+k in c) ])\n```
[]