基本的链表操作,只需一次遍历即可
1 ListNode *deleteDuplicates(ListNode *head) { 2 if(!head) 3 return NULL; 4 ListNode *cur, *next; 5 cur = head; 6 while(cur){ 7 next = cur->next; 8 while(next){ 9 if(next->val != cur->val) 10 break; 11 next = next->next; 12 } 13 cur->next = next; 14 cur = cur->next; 15 } 16 return head; 17 }