Skip to content

Commit c759abd

Browse files
committed
solved: 83
1 parent 81f4396 commit c759abd

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// class ListNode {
2+
// val: number
3+
// next: ListNode | null
4+
// constructor(val?: number, next?: ListNode | null) {
5+
// this.val = (val===undefined ? 0 : val)
6+
// this.next = (next===undefined ? null : next)
7+
// }
8+
// }
9+
10+
// @leet start
11+
/**
12+
* Definition for singly-linked list.
13+
* class ListNode {
14+
* val: number
15+
* next: ListNode | null
16+
* constructor(val?: number, next?: ListNode | null) {
17+
* this.val = (val===undefined ? 0 : val)
18+
* this.next = (next===undefined ? null : next)
19+
* }
20+
* }
21+
*/
22+
23+
function deleteDuplicates(_head: ListNode | null): ListNode | null {
24+
let head = _head;
25+
26+
while(head && head.next) {
27+
/** skip the next node if val is eqal */
28+
if(head.val === head.next.val) head.next = head.next.next;
29+
else head = head.next
30+
}
31+
32+
return _head;
33+
};
34+
// @leet end

0 commit comments

Comments
 (0)