LeetCode: Remove Duplicates from Sorted List

Photo by Waldemar Brandt on Unsplash
/**
* Definition for singly-linked list.
* function ListNode(val, next) {
* this.val = (val===undefined ? 0 : val)
* this.next = (next===undefined ? null : next)
* }
*/
var deleteDuplicates = function(head){
let current = head
}
var deleteDuplicates = function(head){
let current = head
while (head && head.next){
if (head.val == head.next.val) {
head.next = head.next.next
}}}
var deleteDuplicates = function(head){
let current = head
while (head && head.next){
if (head.val == head.next.val) {
head.next = head.next.next
} else {
head = head.next
}
}
return current
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Melissa Guachun

Software Developer and visual artist based in NYC. Join me on my journey to coding enlightenment or a torrential mental breakdown, whichever comes first.