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;
    }
};

相关文章:

  • 2021-06-03
  • 2021-10-24
  • 2021-07-29
  • 2021-08-17
  • 2021-10-17
  • 2022-03-05
  • 2022-01-04
  • 2021-09-21
猜你喜欢
  • 2021-10-01
  • 2022-12-23
  • 2021-08-29
相关资源
相似解决方案