You are viewing a single comment's thread. Return to all comments →
Anybody help, i'm failing only test case 14 , why?
below is the solution:
// Complete the pairs function below. static int pairs(int k, int[] arr) {
Hashtable<Integer,Integer> ht = new Hashtable<>(); int pairs=0; for (int i=0;i<arr.length;i++) { if( ht.containsKey(Math.abs(arr[i]-k) ) ) pairs++; if( ht.containsKey(k+arr[i]) ) pairs++; ht.put(arr[i],i); } return pairs; }
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 →
Anybody help, i'm failing only test case 14 , why?
below is the solution:
// Complete the pairs function below. static int pairs(int k, int[] arr) {