/**
* 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) {
if(head == NULL || head->next == NULL)
return head;
ListNode *pre = new ListNode(0), *cur = head,*next = head->next, *res;
pre->next = head;
res = pre;
while(cur != NULL && next != NULL)
{
if(cur->val == next->val)
{
while((next != NULL) && (cur->val==next->val))
next = next->next;
pre->next = next;
if(next == NULL)
break;
cur = next;
next = next->next;
}
else
{
pre = cur;
cur = next;
next = next->next;
}
}
return res->next;
}
};