/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *deleteDuplicates(ListNode *head) { ListNode *Head = (ListNode *)malloc(sizeof(ListNode)); ListNode *tail = Head,*p1 = head; while(p1){ while(p1->next&&p1->val == p1->next->val) p1 = p1->next;//去重 tail->next = p1; tail = tail->next; p1 = p1->next; } return Head->next; } };