You are viewing a single comment's thread. Return to all comments →
Java using frequency map:
public static int lonelyinteger(List<Integer> a) { if (a.size() == 1) return a.get(0); Map<Integer, Integer> map = new HashMap<>(); for (int i : a) { map.put(i, map.getOrDefault(i, 0) + 1); } int result = 0; for (Map.Entry<Integer,Integer> e : map.entrySet()) { if (e.getValue() == 1) result = e.getKey(); } return result; }
Seems like cookies are disabled on this browser, please enable them to open this website
Lonely Integer
You are viewing a single comment's thread. Return to all comments →
Java using frequency map: