203. Remove Linked List Elements
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
代码如下:
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
public class Solution {
public ListNode removeElements(ListNode head, int val) {
if(head==null)
return null; while(head.val==val&&head.next!=null)
head=head.next; if((head.next==null&&head.val==val))
return null; ListNode p=head; while(p.next!=null)
{
if(p.next.val==val)
p.next=p.next.next;
else p=p.next; }
return head;
}
}
203. Remove Linked List Elements的更多相关文章
- 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题要求 ...
- 203. Remove Linked List Elements【easy】
203. Remove Linked List Elements[easy] Remove all elements from a linked list of integers that have ...
- 203. Remove Linked List Elements - LeetCode
Question 203. Remove Linked List Elements Solution 题目大意:从链表中删除给定的数 思路:遍历链表,如果该节点的值等于给的数就删除该节点,注意首节点 ...
- 【LeetCode】203. Remove Linked List Elements
Remove Linked List Elements Remove all elements from a linked list of integers that have value val. ...
- 【刷题-LeetCode】203. Remove Linked List Elements
Remove Linked List Elements Remove all elements from a linked list of integers that have value *val* ...
- 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 --& ...
- 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 --& ...
随机推荐
- Js笔试题之返回只包含数字类型的数组
如js123ldka78sdasfgr653 => [123,78,653] 一般做法 分析: 1.循环字符串每个字符,是数字的挑出来拼接在一起,不是数字的,就给他空的拼个逗号 2.将新字符串每 ...
- JS访问剪切板中的图片
google出来一个html2canvas,它利用canvas来渲染读取的DOM树,也就是说它只能截取document里的内容,如果要像qq截图那样,应该怎么做?用过百度的Ueditor编辑器的朋友都 ...
- 转: CSS中overflow的用法
Overflow可以实现隐藏超出对象内容,同时也有显示与隐藏滚动条的作用,overflow属性有四个值:visible (默认), hidden, scroll, 和auto.同样有两个overflo ...
- CF 241E flights 最短路,重复迭代直到稳定 难度:3
http://codeforces.com/problemset/problem/241/E 首先检测哪些点会出现在从起点到终点的路上,可以用dfs或者迭代, 然后,对于所有的边,设f为边起点,t为边 ...
- mongo .update
db.classes.update({"count":{$gt:20}},{$set:{"name":"c4"}},false,false) ...
- (DFS)hdoj1010-Tempter of the Bone
#include<cstdio> #include<cmath> #include<stdlib.h> ][]={{,},{,-},{,},{-,}},escape ...
- IT公司100题-13-求链表中倒数第k个结点
问题描述: 输入一个单向链表,输出该链表中倒数第k个结点.链表倒数第0个节点为NULL. struct list_node { int data; list_node* next; }; 分析: 方法 ...
- Xceed WPF 主题皮肤控件Xceed Professional Themes for WPF详细介绍
Xceed Professional Themes for WPF是一款为你的整个应用程序提供完美WPF主题风格的控件,包含Office 2007和Windows 7,可以应用到任何微软官方的WPF控 ...
- 在T-SQL中访问远程数据库(openrowset、opendatasource、openquery)
1. 启用Ad Hoc Distributed Queries 在使用openrowset/opendatasource前要先启用Ad Hoc Distributed Queries服务,因为这个服 ...
- SharePoint 2013 Nintex Workflow 工作流帮助(二)
博客地址 http://blog.csdn.net/foxdave 工作流动作 1. Action Set(Logic and flow分组) 它是一个工作流的集合,可以理解为容器的东西.所以它本身并 ...