• + 0 comments

    my java solution, all tests pass.

    public static int sockMerchant(int n, List ar) { // Write your code here Map map = new HashMap<>(); for(int i=0; i< ar.size(); i++) { if(!map.containsKey(ar.get(i))) map.put(ar.get(i), 1); else { map.put(ar.get(i), map.get(ar.get(i))+1); } } int numPairs=0; Iterator i = map.values().iterator(); while(i.hasNext()) { numPairs = numPairs + (int)i.next()/2; } return numPairs; }