题目:

Remove all elements from a linked list of integers that have value val.

Example
Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6
Return: 1 --> 2 --> 3 --> 4 --> 5

思路:设置前置指针,并随之移动。

代码:

public class Solution {public ListNode removeElements(ListNode head, int val) {ListNode req = new ListNode(0);req.next = head;ListNode pre = req;while(head != null){if(head.val == val){pre.next = head.next;}elsepre = pre.next;head = head.next;}return req.next;}
}

转载于:https://www.cnblogs.com/TinyBobo/p/4543536.html

[LeetCode-JAVA] Remove Linked List Elements相关推荐

  1. leetcode 203. Remove Linked List Elements(链表)

    Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 -- ...

  2. leetcode 203 Remove Linked List Elements

     Remove all elements from a linked list of integers that have valueval. Example Given: 1 --> 2 ...

  3. 【leetcode】Remove Linked List Elements(easy)

    Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 -- ...

  4. LeetCode 203. Remove Linked List Elements

    题目: Remove all elements from a linked list of integers that have value val. Example Given: 1 –> 2 ...

  5. [leetcode]203. Remove Linked List Elements链表中删除节点

    这道题很基础也很重要 重点就是设置超前节点 public ListNode removeElements(ListNode head, int val) {//超前节点ListNode pre = n ...

  6. leetcode python3 简单题203. Remove Linked List Elements

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第二百零三题 (1)题目 英文: Remove all elements from ...

  7. (LeetCode 203)Remove Linked List Elements

    Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 -- ...

  8. [LeetCode]Remove Linked List Elements

    题目描述:(链接) Remove all elements from a linked list of integers that have value val. Example Given: 1 - ...

  9. C#LeetCode刷题之#203-删除链表中的节点(Remove Linked List Elements)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3826 访问. 删除链表中等于给定值 val 的所有节点. 输入: ...

  10. LeetCode Remove Linked List Elements

    题意:删除数组中的指定元素 思路:在遍历链表时,记录前继结点和当前结点,如果胶继结点为空,说明是头结点,当前结点移动时,头结点也随着移动.当要找的结点在链表中时,将前继结点的后继结点修改为当前结点的后 ...

最新文章

  1. Ubuntu 系统禁止或者改变中文简体切换繁体,方便使用AS全局搜索
  2. iOS - MySQL 的安装配置
  3. 大数据的3V和三个层面
  4. redux-form(V7.4.2)笔记(二)
  5. 【通信原理】【实验】实验三: 数字调制解调实验2ASK--2FSK--2PSK思路(GZHU)
  6. MySql中如果某一列中含有NULL,那么包含该列的索引就无效了?
  7. SDNU 1507.E.The Binding of Isaac
  8. js 对 URL 参数进行 加密 解密
  9. 露雨资源库三(第一个.net2.0软件)-为控件增加自动完成功能
  10. java新手笔记3 运算符循环
  11. Android全面解析Handler
  12. java 单链表反转_Java实现单链表翻转详解
  13. 苹果地图副总裁_苹果地图表现糟糕 iOS副总裁福斯特难辞其咎
  14. Windows下定时器与多线程的区别
  15. 实验三 交换机的配置
  16. 论文总结:云安全研究方向及进展综述
  17. 付款码支付-微信和支付宝付款码类型标识
  18. iphone文件服务器权限,苹果手机怎么开启文件共享权限
  19. react native Xcode打包app发布ipa到蒲公英
  20. http://dev.firnow.com/course/3_program/java/javashl/200726/11199.html

热门文章

  1. 关刀机器人_小学机器人活动总结
  2. python 模块和包
  3. RatingBar的自定义
  4. WordPress的RSS订阅优化
  5. SQL Server 2005中的ROW_NUMBER和RANK
  6. 5位数的数字黑洞是多少_每日一题[491]数字黑洞--Kaprekar常数
  7. 面试必备:多线程学习(一)
  8. Android百度云推送接入,附完整代码
  9. vue-cli 3.0 怎么配置 webpack.ProvidePlugin
  10. 使用WINPE在硬盘安装WIN7系统