Linked List
JavaScript
View CodeThis is a sample problem using a Linked List.
Linked Lists!
Add something to the Linked List!
The duplicate removal algorithm is implemented with an O(n) solution using a Map:
1class LinkedList {2 ...34 removeDuplicates() {5 let previouslySeen = new Map();67 let iterations = this.count;8 let current = this.head;9 let prev = this.head;1011 for (let i = 0; i < iterations; i++) {12 if (previouslySeen.has(current.value)) {13 if (current.next) {14 prev.next = current.next;15 } else {16 prev.next = null;17 }1819 this.decrementCount();20 } else {21 previouslySeen.set(current.value, current);22 prev = current;23 }2425 current = current.next;26 }27 }2829 ...30}31