```
public int findPairs(int[] nums, int k) {
int result = 0;
Arrays.sort(nums);
for (int i = 0; i < nums.length - 1; i++) {
if (i != 0 && nums[i] == nums[i - 1]) continue; // have the same
for (int j = i + 1; j < nums.length; j++) {
if (nums[i] + k == nums[j]) {
result++;
break;
}
}
}
return result;
}
}
```