-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patho_solution.js
50 lines (45 loc) · 877 Bytes
/
o_solution.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class ListNode {
constructor(val, next) {
this.val = (val === undefined ? 0 : val);
this.next = (next === undefined ? null : next);
}
}
/**
* @param {ListNode} head
* @return {ListNode}
*/
const deleteDuplicates = (head) => {
let result = head;
while (head) {
let curr = head;
while (head.next && curr.val === head.next.val) {
head.next = head.next.next;
}
head = head.next;
}
console.log("result")
// console.log(result)
while (result) {
console.log(result.val)
result = result.next;
}
return result;
}
deleteDuplicates(
new ListNode(1,
new ListNode(1,
new ListNode(1,
new ListNode(2,
new ListNode(2,
new ListNode(2,
new ListNode(3,
new ListNode(3
)
)
)
)
)
)
)
)
)