0082.cpp (481B)
1 class Solution { 2 public: 3 ListNode *deleteDuplicates(ListNode *head) { 4 ListNode top(-200, head); 5 6 for (ListNode *p = &top, *c = head; c && c->next; c = c->next) { 7 if (c->val == c->next->val) { 8 while (c && c->next && c->val == c->next->val) 9 c = c->next; 10 p->next = c->next; 11 if (!c) break; 12 } else 13 p = p->next; 14 } 15 16 return top.next; 17 } 18 };