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