Skip to content

Commit 44a9a96

Browse files
committedMay 11, 2022
Time: 133 ms (10.89%), Space: 44.7 MB (9.71%) - LeetHub
1 parent d829f1b commit 44a9a96

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* function ListNode(val, next) {
4+
* this.val = (val===undefined ? 0 : val)
5+
* this.next = (next===undefined ? null : next)
6+
* }
7+
*/
8+
/**
9+
* @param {ListNode} head
10+
* @return {ListNode}
11+
*/
12+
var deleteDuplicates = function(head) {
13+
if(!head) return null;
14+
let prev = head;
15+
let current= head.next;
16+
while(current){
17+
if(current.val==prev.val){
18+
prev.next= current.next;
19+
}else {
20+
prev= prev.next;
21+
}
22+
23+
current=current.next;
24+
25+
}
26+
27+
return head
28+
};

0 commit comments

Comments
 (0)
Please sign in to comment.