ListNode* removeElements(ListNode* head, int val)
{
    if (head == NULL)
        return head;
    
    ListNode *p = head;
    while (p && p->val==val)
    {
        p = p->next;
    }

    if (p)
    {
        ListNode *q=p;
        ListNode *temp = p->next;
        while (temp)
        {
            if (temp->val != val)
            {
                q->next = temp;
                q=q->next;
            }
            else
            {
                q->next = temp->next;
            }
            temp = temp->next;
        }
    }
    return p;
}

 

相关文章:

  • 2021-12-23
  • 2022-01-04
  • 2021-09-04
  • 2021-07-05
  • 2021-10-04
猜你喜欢
  • 2021-07-02
  • 2021-11-20
  • 2021-07-21
  • 2021-10-26
  • 2021-06-11
  • 2022-01-31
相关资源
相似解决方案