Files
CS-Notes/notes/18.2 删除排序链表中重复的结点.md
xie140240318 4b9ec3e4ef Update and rename 18.2 删除链表中重复的结点.md to 18.2 删除排序链表中重复的结点.md
题目描述错误,题目中的链表应为排序后的链表
2020-03-26 23:11:31 +08:00

1003 B

18.2 删除排序链表中重复的结点

NowCoder

题目描述


解题描述

public ListNode deleteDuplication(ListNode pHead) {
    if (pHead == null || pHead.next == null)
        return pHead;
    ListNode next = pHead.next;
    if (pHead.val == next.val) {
        while (next != null && pHead.val == next.val)
            next = next.next;
        return deleteDuplication(next);
    } else {
        pHead.next = deleteDuplication(pHead.next);
        return pHead;
    }
}