203 移除链表元素

    ListNode *removeElements(ListNode *head, int val) {
        if (head == nullptr)
            return head;
        auto *prehead = new ListNode(-1);
        prehead->next = head;
        head = prehead;
        while (head&&head->next) {
            if (head->next->val == val)
                head->next = head->next->next;
            else
                head = head->next;
        }
        return prehead->next;
    }
原文地址:https://www.cnblogs.com/INnoVationv2/p/10176728.html