Easy to understand 2 pointer / sliding window approach in python O(1) space, O(nlogn) time
\n    def findPairs(self, nums, k):\n        """\n        :type nums: List[int]\n        :type k: int\n        :rtype: int\n        """\n        count = 0\n    
```\n    def findPairs(self, nums, k):\n        """\n        :type nums: List[int]\n        :type k: int\n        :rtype: int\n        """\n        count = 0\n        nums.sort()\n        \n        slow = 0\n        fast = 1\n        size = len(nums)\n        \n        while fast < size:\n            if nums[fast] - nums[slow] < k: # case 1, diff is less than k\n                fast += 1\n            elif nums[fast] - nums[slow] > k: # case 2, diff is greater than k\n                slow += 1\n            else: # case 3, diff is equal to k so increment the count!\n                count += 1\n                fast += 1\n                slow += 1\n                \n                #Now ignore any duplicates, both slow and fast could be pointing to duplicates\n                while slow < size-1 and nums[slow] == nums[slow-1]:\n                    slow += 1\n                    \n                while fast < size-1 and nums[fast] == nums[fast-1]:\n                    fast += 1\n                    \n            if fast <= slow: # fast should be atleast one more than slow\n                fast = slow + (slow - fast) + 1\n                \n        return count\n\t\t\t\t\n```
[]