[leetcode]203. Remove Linked List Elements链表中删除节点
这道题很基础也很重要
重点就是设置超前节点
public ListNode removeElements(ListNode head, int val) {
//超前节点
ListNode pre = new ListNode(0);
pre.next = head;
ListNode res = pre;
while (pre!=null&&pre.next!=null)
{
if (pre.next.val==val)
{
pre.next = pre.next.next;
//注意这里要跳出循环,因为节点已经跳跃一位了,不需要再更新超前节点
continue;
}
pre = pre.next;
}
//这里不能返回head,因为head可能已经被孤立出来了
return res.next;
}
[leetcode]203. Remove Linked List Elements链表中删除节点的更多相关文章
- Leetcode 203 Remove Linked List Elements 链表
去掉链表中相应的元素值 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next ...
- leetcode 203. Remove Linked List Elements 、83. Remove Duplicates from Sorted List 、82. Remove Duplicates from Sorted List II(剑指offer57 删除链表中重复的结点)
203题是在链表中删除一个固定的值,83题是在链表中删除重复的数值,但要保留一个:82也是删除重复的数值,但重复的都删除,不保留. 比如[1.2.2.3],83题要求的结果是[1.2.3],82题要求 ...
- LeetCode 203. Remove Linked List Elements (移除链表中的项)
Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...
- LeetCode 203. Remove Linked List Elements 移除链表元素 C++/Java
Remove all elements from a linked list of integers that have value val. Example: Input: ->->-& ...
- [LeetCode] 203. Remove Linked List Elements 移除链表元素
Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...
- Java [Leetcode 203]Remove Linked List Elements
题目描述: Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> ...
- [LeetCode] 203. Remove Linked List Elements 解题思路
Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...
- Java for LeetCode 203 Remove Linked List Elements
Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 -- ...
- (easy)LeetCode 203.Remove Linked List Elements
Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...
随机推荐
- VS2019配置C+++mingW32配置
两个安装教程博客 http://t.sg.cn/yq22mn http://t.sg.cn/wsavo0 基于调试报错,是因为文件夹是中文,贴一个详细的博客:http://t.sg.cn/3j5e4z
- LeetCode 046 Permutations
题目要求:Permutations(全排列) Given a collection of numbers, return all possible permutations. For example, ...
- Bootstrap(修改中)
表格 斑马表格 <table class="table-striped"> </table> 鼠标经过表格的hover效果 <table class= ...
- 010 editor的使用
原文链接:http://www.cnblogs.com/vendanner/p/4939444.html 注意事项:之前一直在虚拟机winxp中添加template一直失败,原因可能是因为虚拟机的版本 ...
- JZOJ2020年10月5日提高B组反思
2020年10月5日提高B组反思 T1 考试的时候想简单了 觉得把跟没有攻占的点相连的边留下就可以了 没有考虑到最小 WA&RE 10 T2 没有思路 就直接从中间往后枚举分解处 蜜汁错误 W ...
- Windows下django项目部署 通过Apache2.4+mod_wsgi
经过几天踩坑,记录在Windows10下通过Apache2.4部署Django项目的过程 运行环境: 先说下环境,怎么安装倒是其次的,版本很重要,我是根据mod_wsgi的版本要求下载的各个版本(py ...
- day1(初始化项目结构)
1.初始化项目结构 └─shiyanlou_project │ .gitignore │ README.en.md # 英文 │ README.md ...
- Python正则运算符优先级re.findall('(.)*',"abc")、re.findall('(.*)',"abc")、re.findall('(.?)*',"abc")的执行结果的影响分析
我们分别执行三个语句: >>> re.findall('(.)*',"abc") ['c', ''] >>> re.findall('(.*)' ...
- python 读取excel表格内不同类型的数据
不同类型数据对应值: #coding=utf-8 import os import xlrd from datetime import datetime,date newparh = os.chdir ...
- 串口数据监视-Bus Hound
Bus Hound使用说明 一.打开该工具,会看到最上面的六个图标:1.Capture(捕捉按钮):按下它选择捕捉数据界面2.Save(保存按钮):按下它选择保存数据界面3.Setting(设置按钮) ...