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