剑指offer---删除链表中重复的结点

class Solution {
public:
    ListNode* deleteDuplication(ListNode* pHead)
    {
    
        if (pHead == NULL) return pHead;
        if (pHead->next == NULL)    return pHead;
        int First = pHead->val;
        ListNode* head = new ListNode(First + 1);
        head->next = NULL;
        head->next = pHead;

        ListNode* Cur=head;
        ListNode* Next=Cur->next;

        while (Next != NULL)
        {
            while ((Next->next != NULL) && (Next->next->val == Next->val))
            {
                Next = Next->next;
            }
            if (Cur->next != Next)
            {
                Next = Next->next;
                Cur->next = Next;
            }
            else
            {
                Cur = Next;
                Next = Next->next;
            }

        }
        return head->next;
        




    }
};
原文地址:https://www.cnblogs.com/159269lzm/p/7260534.html