ListNode *deleteDuplicates(ListNode *head) {
if (head == nullptr || head->next == nullptr)
return head;
ListNode prehead(-1);
prehead.next = head;
head = &prehead;
ListNode *left, *right;
while (head->next) {
left = head->next;
right = left;
while (right->next && right->next->val == left->val)
right = right->next;
if (left == right)
head = head->next;
else
head->next = right->next;
}
return prehead.next;
}
原文地址:https://www.cnblogs.com/INnoVationv2/p/10176351.html
时间: 2024-10-04 06:46:29