题解 | #删除有序链表中重复的元素-II#
删除有序链表中重复的元素-II
https://www.nowcoder.com/practice/71cef9f8b5564579bf7ed93fbe0b2024
class Solution { public: ListNode* deleteDuplicates(ListNode* head) { if(!head) return head; ListNode *res=new ListNode(-1); res->next=head; ListNode *cur=res; while(cur->next&&cur->next->next){ if(cur->next->val==cur->next->next->val){ int tmp=cur->next->val; while(cur->next->val==tmp&&cur->next!=NULL){ cur->next=cur->next->next; } } else cur=cur->next; } return res->next; } };