0
点赞
收藏
分享

微信扫一扫

[Leetcode] 82. Remove Duplicates from Sorted List II

乐百川 2022-02-20 阅读 99
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    unordered_map<int, int> um;
    ListNode* deleteDuplicates(ListNode* head) {

        if(head == NULL) return head;

        ListNode * dummy = new ListNode(-101, head);
        ListNode * current = dummy;

        while(current->next != NULL && current->next->next != NULL){
            int tmp = -101;
            if(current->next->val == current->next->next->val){
                tmp = current->next->val;
                while(current->next != NULL && current->next->val == tmp){
                    current->next = current->next->next;
                }
            }
            else{
                current = current->next;
                tmp = -101;
            }
        }
        return dummy->next;
    }
};

:D 记录的第二天 等这几天忙完把思路补上

举报

相关推荐

0 条评论