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;
    }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-12
  • 2020-04-11
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
  • 2021-07-13
猜你喜欢
  • 2020-12-31
  • 2021-07-15
  • 2022-02-26
  • 2021-08-11
相关资源
相似解决方案