单链表节点删除

删除链表的节点。

struct ListNode
{
   int val;
   ListNode* next;
   ListNode(int x):val(x),next(NULL){}
};

calss Solution
{
  public:
  ListNode* deleteNode(ListNode* head,int val)
  {
     if(head->val==val) return head->next;
     ListNode* p=head;
     while(p->next->val!=val)
     {
       p=p->next;
     }
     p->next=p->next->next;
     return head;
  }
};

发布了22 篇原创文章 · 获赞 1 · 访问量 335

猜你喜欢

转载自blog.csdn.net/weixin_43086349/article/details/104691226