您当前的位置: 首页 >  leetcode

LeetCode Algorithm 203. 移除链表元素

发布时间:2021-12-11 02:03:56 ,浏览量:0

203. 移除链表元素

Ideas

这题其实很简单,从头开始遍历,只要遇到node->val==val的通通删除就OK了。

Code C++
class Solution { public: ListNode* removeElements(ListNode* head, int val) { ListNode* pre = new ListNode(0, head); ListNode* item = pre; while (item->next != NULL) { if (item->next->val == val) { item->next = item->next->next; } else { item = item->next; } } return pre->next; } }; 
关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    108697博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0468s