-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path082.js
More file actions
35 lines (34 loc) · 733 Bytes
/
082.js
File metadata and controls
35 lines (34 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
* @param {ListNode} head
* @return {ListNode}
*/
var deleteDuplicates = function(head) {
let result = null;
let resultTail = null;
while(head) {
const currentValue = head.val;
if (head.next && head.next.val === currentValue) {
while(head && head.val === currentValue) {
head = head.next;
}
} else {
if (resultTail === null) {
result = head;
resultTail = head;
} else {
resultTail.next = head;
resultTail = head;
}
head = head.next;
}
}
resultTail && (resultTail.next = null);
return result;
};;