基本模拟题
代码:
1 ListNode *deleteDuplicates(ListNode *head) { 2 if (!head) 3 return head; 4 5 ListNode *h = NULL; 6 ListNode *t = NULL; 7 ListNode *c = head; 8 9 while (c) { 10 bool dup = false; 11 while (c->next && c->val == c->next->val) { 12 dup = true; 13 c = c->next; 14 } 15 if (!dup) { 16 if (!h) 17 h = t = c; 18 else { 19 t->next = c; 20 t = t->next; 21 } 22 } 23 c = c->next; 24 } 25 if (t) 26 t->next = NULL; 27 28 return h; 29 }