/**
 * struct ListNode {
 *	int val;
 *	struct ListNode *next;
 * };
 *
 * C语言声明定义全局变量请加上static,防止重复定义
 */
/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 *
 * 
 * @param pHead ListNode类 
 * @return ListNode类
 */

struct ListNode *deleteDuplication(struct ListNode *pHead)
{
    struct ListNode *vHead;
    vHead = (struct ListNode *)malloc(sizeof(struct ListNode));
    vHead->next = pHead;
    //定义虚头结点方便边界情况讨论
    struct ListNode *pre, *cur;
    pre = vHead, cur = pHead;

    while (cur)
    {
        if (cur->next && cur->val == cur->next->val)
        {
            cur = cur->next;
            while (cur->next && cur->val == cur->next->val)
                cur = cur->next;
        //当遇到与下一节点值相同时,cur推进到最后一个重复的数字处
        //本数字舍去,pre连接到下一个
            cur = cur->next;
            pre->next = cur;
        }
        //遇到与下一节点值不同或者是没有下一节点时,pre移动到此处,cur继续后移
        else if(!cur->next || cur->val != cur->next->val)
        {
            pre = cur;
            cur = cur->next;
        }
    }
    return vHead->next;
}