You are viewing a single comment's thread. Return to all comments →
Hi, I'll upload my java solution
public static int pairs(int k, List<Integer> arr) { Collections.sort(arr); int answer = 0; int i = 0, j = i+1; for(i = 0; i < arr.size()-1; i++){ while(j<arr.size()){ int fir = arr.get(i); int sec = arr.get(j); if(sec - fir == k){ answer++; }else if(sec - fir > k){ break; } j++; } } return answer; }
`
Pairs
You are viewing a single comment's thread. Return to all comments →
Hi, I'll upload my java solution
`