【leetcode】移除重复节点

 

struct ListNode* removeDuplicateNodes(struct ListNode* head){
    int hash[20001] = {0};
    struct ListNode* node = head;
    struct ListNode* pre = NULL;
    while(node)
    {
        if (!hash[node->val])
        {
            hash[node->val]++;
        }
        else
        {
            pre->next = node->next;
            node = node->next;
            continue;
        }
        pre = node;
        node = node->next;
    }
    return head;
}

 

posted @ 2020-09-09 11:37  温暖了寂寞  阅读(125)  评论(0编辑  收藏  举报