Skip to content

Commit 6d19821

Browse files
authored
Update 83-remove-duplicates-from-sorted-list.js
1 parent 600e1d9 commit 6d19821

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

83-remove-duplicates-from-sorted-list.js

+28
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,31 @@ const deleteDuplicates = function(head) {
2020
}
2121
return head;
2222
};
23+
24+
// another
25+
26+
/**
27+
* Definition for singly-linked list.
28+
* function ListNode(val, next) {
29+
* this.val = (val===undefined ? 0 : val)
30+
* this.next = (next===undefined ? null : next)
31+
* }
32+
*/
33+
/**
34+
* @param {ListNode} head
35+
* @return {ListNode}
36+
*/
37+
const deleteDuplicates = function(head) {
38+
let prev = null, cur = head
39+
while(cur) {
40+
if(prev && prev.val === cur.val) {
41+
prev.next = cur.next
42+
cur = cur.next
43+
} else {
44+
prev = cur
45+
cur = cur.next
46+
}
47+
}
48+
return head
49+
};
50+

0 commit comments

Comments
 (0)