You are viewing a single comment's thread. Return to all comments →
Using Java stream
public static int sockMerchant(int n, List<Integer> ar){ Map<Integer, Integer> map = ar.stream().map(i -> new AbstractMap.SimpleEntry<>(i, 1)).collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue, Integer::sum)); return map.values().stream().mapToInt(integer -> integer / 2).sum(); }
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 →
Using Java stream