[Python] O(n) solution, explained
Let us just use counter and count frequency of each number in our array. We can have two options:\n\n1. k > 0, it means, that for each unique number i we are as
Let us just use counter and count frequency of each number in our array. We can have two options:\n\n1. `k > 0`, it means, that for each unique number `i` we are asking if number `i+k` also in table.\n2. `k = 0`, it means, that we are looking for pairs of equal numbers, so just check each frequency.\n\n**Complexity**: time and space complexity is `O(n)`, because we traverse our array twice: first time to create counter and second to find `res`.\n\n```\nclass Solution:\n    def findPairs(self, nums, k):\n        count = Counter(nums)\n        if k > 0:\n            res = sum([i + k in count for i in count])\n        else:\n            res = sum([count[i] > 1 for i in count])\n        return res\n```\n\nIf you have any questions, feel free to ask. If you like solution and explanations, please **Upvote!**
[]