1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 1 2 2 2 2 15 5 10 10 2 1 | //2.1 Remove dups from unsorted linked list //this implementation only works for numbers var deDupe = function(head) { var items = []; var current = head; items[current.data] = true; while(current.next != null) { if(items[current.next.data]) { current.next = current.next.next; //remove dup from list } else { items[current.next.data] = true; current = current.next; } } return head; }; module.exports = deDupe; |