Morgan Stanley interview question

Write a method in java to remove duplicates from a generic list.

Interview Answer

Anonymous

17 Dec 2016

HashMap duplicates = new HashMap(); for (T obj : list) { if (duplicates.containsKey(obj)) return obj; else duplicates.put(obj, 1); }