class Solution { public: ListNode* deleteDuplication(ListNode* pHead) { if (pHead == NULL) return pHead; if (pHead->next == NULL) return pHead; int First = pHead->val; ListNode* head = new ListNode(First + 1); head->next = NULL; head->next = pHead; ListNode* Cur=head; ListNode* Next=Cur->next; while (Next != NULL) { while ((Next->next != NULL) && (Next->next->val == Next->val)) { Next = Next->next; } if (Cur->next != Next) { Next = Next->next; Cur->next = Next; } else { Cur = Next; Next = Next->next; } } return head->next; } };
时间: 2024-12-26 07:52:39