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