/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param pHead ListNode类
* @return ListNode类
*/
struct ListNode* deleteDuplication(struct ListNode* pHead) {
struct ListNode* newhead = (struct ListNode*)malloc(sizeof(struct ListNode));
if (pHead == NULL)return NULL;
struct ListNode* newtail = newhead;
newhead->next =NULL;
struct ListNode* cur = pHead;
if (pHead->next == NULL)return pHead;
struct ListNode* next = cur->next;
while (cur)
{
if (!next&&!cur)return newhead->next;
if (next&&cur->val == next->val)
{
while (next&&cur->val==next->val)
{
if (next)
next = next->next;
}
cur = next;
if (next)
next = next->next;
}
else
{
newtail->next = cur;
newtail = cur;
newtail->next = NULL;
cur = next;
if (next)
next = next->next;
}
}
return newhead->next;
}