Python concise O(N) solution using sets, only one pass through the list
Check whether num + k and num - k are already in the set and also make sure the pair is not already counted. Only goes throught the list one time.\n\nEdit: afte
Check whether num + k and num - k are already in the set and also make sure the pair is not already counted. Only goes throught the list one time.\n\nEdit: after reading other solutions, some memory can be saved by only saving the smallest value between num1 and num2 in pairsSet instead of the sorted tuple.\n```\nclass Solution(object):\n    def findPairs(self, nums, k):\n        if k < 0: return 0\n        numsSet, pairsSet = set(), set()\n        for num1 in nums:\n            for num2 in [num1 + k, num1 - k]:\n                if num2 in numsSet:\n                    pairsSet.add(tuple(sorted([num1, num2])))\n            numsSet.add(num1)\n        return len(pairsSet)\n```
['Python']