VMware Coding Challenge: Removing Duplicates Entries
1 static LinkedListNode removeDuplicates(LinkedListNode list) { 2 LinkedListNode cur = list; 3 HashSet<Integer> set = new HashSet<Integer>(); 4 set.add(list.val); 5 while (cur.next != null) { 6 if (!set.contains(cur.next.val)) { 7 set.add(cur.next.val); 8 cur = cur.next; 9 } 10 else { 11 cur.next = cur.next.next; 12 } 13 } 14 return list; 15 16 }