尼采般地抒情

尼采般地抒情

尼采般地抒情

音乐盒

站点信息

文章总数目: 315
已运行时间: 1554


typescript

/**
 * Definition for singly-linked list.
 * class ListNode {
 *     val: number
 *     next: ListNode | null
 *     constructor(val?: number, next?: ListNode | null) {
 *         this.val = (val===undefined ? 0 : val)
 *         this.next = (next===undefined ? null : next)
 *     }
 * }
 */

function deleteDuplicates(head: ListNode | null): ListNode | null {
if (!head) return head
const firstNode = new ListNode(-1, head);
let curr = firstNode;
while (curr.next && curr.next.next) {
if (curr.next.val === curr.next.next.val) {
const temp = curr.next.val
while (curr.next && curr.next.val === temp)
curr.next = curr.next.next;
} else {
curr = curr.next;
}
}
return firstNode.next;
};

评论区