You are viewing a single comment's thread. Return to all comments →
Java implementation
static int pairs(int k, int[] arr) { int sum =0; Set<Integer> set = new HashSet<Integer>(); for(int n=0; n< arr.length; n++){ set.add(arr[n]); } for(int n=0; n< arr.length; n++){ if(set.contains(arr[n]+k)){ sum+=1; } } return sum; }
Seems like cookies are disabled on this browser, please enable them to open this website
Pairs
You are viewing a single comment's thread. Return to all comments →
Java implementation