劍指offer---刪除鏈表中重復的結點
阿新 • • 發佈:2017-07-30
== blog while logs div cati lis ext 刪除
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; } };
劍指offer---刪除鏈表中重復的結點