You are viewing a single comment's thread. Return to all comments →
This is my Java solution, feel free to ask me any questions.
public static int sockMerchant(int n, List<Integer> ar) { Map<Integer, Integer> sockMap = new HashMap<>(); //Perform counting socks for(int sock : ar) { int frequency = sockMap.getOrDefault(sock, 0); sockMap.put(sock, frequency + 1); } int pairs = 0; for(int frequency : sockMap.values()) { if(frequency >= 2) pairs += frequency/2; } return pairs; }
Seems like cookies are disabled on this browser, please enable them to open this website
Sales by Match
You are viewing a single comment's thread. Return to all comments →
This is my Java solution, feel free to ask me any questions.