https://leetcode.com/problems/remove-duplicates-from-sorted-list/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
* @param {ListNode} head
* @return {ListNode}
*/
var deleteDuplicates = function(head) {
let p = head
while(p) {
if (p.next && p.val === p.next.val) {
p.next = p.next.next
} else {
p = p.next
}
}
return head
};