-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.js
More file actions
35 lines (34 loc) · 826 Bytes
/
solution.js
File metadata and controls
35 lines (34 loc) · 826 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 node = head,
tempNode = null
head = null
while (node !== null) {
let hasDuplicate = false
while (node.next && node.val === node.next.val) {
hasDuplicate = true
node = node.next
}
if (hasDuplicate === false) {
if (tempNode === null) {
tempNode = new ListNode(node.val)
head = tempNode
} else {
tempNode.next = new ListNode(node.val)
tempNode = tempNode.next
}
}
node = node.next
}
return head
};