ListNode* deleteDuplication(ListNode* pHead)
{
// 解法2:每次找一个不重复的元素,加入链表
if (pHead == nullptr)
return pHead;
ListNode *newhead = new ListNode(1);
ListNode *index = newhead;
ListNode *p = pHead;
bool rept = false;
while (p != nullptr){
rept = false;
while (p->next != nullptr && p->val == p->next->val){
rept = true;
p = p->next;
}
if (rept == false){
index->next = new ListNode(p->val);
index = index->next;
p = p->next;
}
else{
if (p->next == nullptr){
break;
}
else{
p = p->next;
}
}
}
return newhead->next;
}