1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| class Solution { public: ListNode* deleteDuplicates(ListNode* head) { if (!head) return head; ListNode* dummyHead = new ListNode(0, head); ListNode* curr = dummyHead; while (curr->next && curr->next->next) { if (curr->next->val == curr->next->next->val) { int x = curr->next->val; curr->next = curr->next->next->next; while(curr->next && curr->next->val == x) curr->next = curr->next->next; } else { curr = curr->next; } } return dummyHead->next; } };
|