标签:list while val 存在 desc lis ret 删除链表 pre
1 class Solution { 2 public: 3 ListNode* deleteDuplication(ListNode* pHead) { 4 if (pHead == nullptr || pHead->next == nullptr)return pHead; 5 ListNode *newHead = new ListNode(0); 6 newHead->next = pHead; 7 ListNode *pre = newHead, *p = newHead->next; 8 int sameNum = 0; 9 while (p!= nullptr && p->next != nullptr) 10 { 11 if (p->val == p->next->val) 12 { 13 sameNum = p->val; 14 while (pre->next != nullptr && pre->next->val == sameNum) 15 pre->next = pre->next->next; 16 p = pre->next; 17 } 18 else 19 { 20 pre = p; 21 p = p->next; 22 } 23 } 24 return newHead->next; 25 } 26 };
标签:list while val 存在 desc lis ret 删除链表 pre
原文地址:https://www.cnblogs.com/zzw1024/p/11657470.html