Last active
October 24, 2022 03:05
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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