Simple Idea O(nlogn) time + O(1) space Java Solution
guess this solution is intuitive.\n\npublic class Solution {\n    public int findPairs(int[] nums, int k) {\n        if (nums == null || nums.length < 2) return
guess this solution is intuitive.\n```\npublic class Solution {\n    public int findPairs(int[] nums, int k) {\n        if (nums == null || nums.length < 2) return 0;\n        int res = 0;\n        Arrays.sort(nums);\n        for (int i = 0; i < nums.length; i++) {\n            if (i > 0 && nums[i] == nums[i - 1]) continue;\n            if (helper(nums, i + 1, nums[i] + k)) res++;\n        }\n        return res;\n    }\n    private boolean helper(int[] nums, int l, int target) {\n        int r = nums.length - 1;\n        while (l <= r) {\n            int mid = l + (r - l) / 2;\n            if (nums[mid] == target) return true;\n            if (nums[mid] < target) l = mid + 1;\n            else r = mid - 1;\n        }\n        return false;\n    }\n}\n```
[]