82.Remove Duplicates from Sorted List II

Posted smallredness

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了82.Remove Duplicates from Sorted List II相关的知识,希望对你有一定的参考价值。

class Solution {
public:
    ListNode *deleteDuplicates(ListNode *head) {
        if (!head || !head->next) return head;
        ListNode *dummy = new ListNode(-1), *pre = dummy;
        dummy->next = head;
        while (pre->next) {
            ListNode *cur = pre->next;
            while (cur->next && cur->next->val == cur->val) {
                cur = cur->next;
            }
            if (cur != pre->next) pre->next = cur->next;
            else pre = pre->next;
        }
        return dummy->next;
    }
};

以上是关于82.Remove Duplicates from Sorted List II的主要内容,如果未能解决你的问题,请参考以下文章

82. Remove Duplicates from Sorted List II

82. Remove Duplicates from Sorted List II(js)

82. Remove Duplicates from Sorted List II

82. Remove Duplicates from Sorted List II

82. Remove Duplicates from Sorted List II

82. Remove Duplicates from Sorted List II