O(N), very easy way by using hashset
\tfrom typing import List\n\n\n\tclass Solution:\n\t\tdef findPairs(self, nums: List[int], k: int) -> int:\n\t\t\tif k < 0:\n\t\t\t\treturn 0\n\n\t\t\tsaw = set
\tfrom typing import List\n\n\n\tclass Solution:\n\t\tdef findPairs(self, nums: List[int], k: int) -> int:\n\t\t\tif k < 0:\n\t\t\t\treturn 0\n\n\t\t\tsaw = set()\n\t\t\tpair = set()\n\n\t\t\tfor num in nums:\n\t\t\t\tif num + k in saw:\n\t\t\t\t\tpair.add((min(num + k, num), max(num + k, num)))\n\n\t\t\t\tif num - k in saw:\n\t\t\t\t\tpair.add((min(num - k, num), max(num - k, num)))\n\n\t\t\t\tsaw.add(num)\n\n\t\t\treturn len(pair)\n
['Python3']