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;
}
*** 82 删除排序链表中的重复元素II
猜你喜欢
转载自www.cnblogs.com/INnoVationv2/p/10176351.html
今日推荐
周排行