Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save lienista/08fd550b0448e1e3db846ef47998b707 to your computer and use it in GitHub Desktop.

Select an option

Save lienista/08fd550b0448e1e3db846ef47998b707 to your computer and use it in GitHub Desktop.
(Algorithms in Javascript) Leetcode 83. Remove Duplicates from Sorted List - Given a sorted linked list, delete all duplicates such that each element appear only once.
const removeDuplicates = (head) => {
let current = head;
let numList = {};
numList[current.val] = 1;
while (current != null && current.next != null) {
if (numList[current.next.val]) {
current.next = current.next.next;
} else {
current = current.next;
numList[current.val] = 1;
}
}
return head;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment