```
public class Solution {
public int findPairs(int[] nums, int k) {
Arrays.sort(nums);
int count = 0;
for (int i = 0; i < nums.length; i++) {
if (i > 0 && nums[i - 1] == nums[i]) continue;
for (int j = i + 1; j < nums.length; j++) {
if (nums[i] + k == nums[j]) {
count++;
break;
}
if (nums[i] + k < nums[j])
break;
}
}
return count;
}
}
```