leetcode 82. Remove Duplicates from Sorted List II

来源:互联网 发布:linux 查看snmp配置 编辑:程序博客网 时间:2024/06/10 01:38
class Solution {public:ListNode* deleteDuplicates(ListNode* head) {ListNode *res = new ListNode(0); //dummy headListNode *tail=res, *temp;temp = head;while (temp){if (temp->next==nullptr || temp->val != temp->next->val){tail->next = temp;tail = temp;temp = temp->next;}else{int val = temp->val;while (temp && temp->val == val){temp = temp->next;}}}tail->next = nullptr;return res->next;}};

0 0