/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};
*/
class Solution {
public:
ListNode* nextNode(ListNode* pHead){//找下一个不重复结点
if(!pHead)
return NULL;
ListNode *p=pHead;
bool flag=0;
while(p->next){
if(p->val==p->next->val){
flag=1;
p=p->next;
}
else if(flag){
flag=0;
p=p->next;
}
else
break;
}
if(!flag)
return p;
return NULL;
}
ListNode* deleteDuplication(ListNode* pHead) {
ListNode *head=nextNode(pHead),*p=head,*q=head;
if(!head)
return NULL;
while(p->next){
p=nextNode(p->next);
q->next=p;
if(!p)
break;
q=q->next;
}
return head;
}
};