(LinkedList) 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) {
while(head!=null && head.val==val)
head=head.next;
if(head==null)
return head;
ListNode cur=head;
while(cur!=null && cur.next!=null){
if(cur.next.val==val){
cur.next=cur.next.next;
}
else
cur=cur.next;
}
return head;
}
}
(LinkedList) Remove Linked List Elements的更多相关文章
- (LeetCode 203)Remove Linked List Elements
Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...
- 203. Remove Linked List Elements【easy】
203. Remove Linked List Elements[easy] Remove all elements from a linked list of integers that have ...
- [LintCode] Remove Linked List Elements 移除链表元素
Remove all elements from a linked list of integers that have value val. Have you met this question i ...
- Leetcode-203 Remove Linked List Elements
#203. Remove Linked List Elements Remove all elements from a linked list of integers that have val ...
- 【LeetCode】237 & 203 - Delete Node in a Linked List & Remove Linked List Elements
237 - Delete Node in a Linked List Write a function to delete a node (except the tail) in a singly l ...
- 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 Linked List Elements Remove all elements from a linked list of integers that have value val. ...
- LeetCode Remove Linked List Elements 删除链表元素
题意:移除链表中元素值为val的全部元素. 思路:算法复杂度肯定是O(n),那么就在追求更少代码和更少额外操作.我做不出来. /** * Definition for singly-linked li ...
- LeetCode_203. Remove Linked List Elements
203. Remove Linked List Elements Easy Remove all elements from a linked list of integers that have v ...
随机推荐
- .htaccess设置自定义出错页面
404错误可以这么写 ErrorDocument code error.php 如果是404错误,跳到文件error.php 其他常用错误页面写法(其中404错误有2种写法,上面一种,下面是通用错误定 ...
- 运放——压摆率SR的意义和如何选取
http://blog.csdn.net/dxshappy/article/details/8065798
- 安装64位mysql5.626
计算机--右击属性--左上高级系统变量---环境变量 path 添加 mysql 的bin目录 ;D:\mysqlwinx64\bin1 //mysql 5.6.26安装前先解压到d盘根目录 cd D ...
- iOS开发中的数据安全隐患和解决方案
移动互联网的兴起,每天都会涌现大量的app产品,无论公司开发还是个人开发,大家都在追求更快的抢占市场,但是确忽略了打磨产品,也忽略了移动开发中的数据安全隐患,如果我们用Charles工具,很容易截获到 ...
- css3 弹框提示样式
.common-dialog-box{ opacity: 0; filter: alpha(opacity=0); position: fixed; top: 0%; left: 50%; z-ind ...
- animate.css总结
本文对animate.css的各个效果进行总结 bounce 从上掉落,在地上小幅度跳起 <!DOCTYPE html> <meta charset="utf-8" ...
- android sdk 更新用的HOSTS
74.125.113.121 developer.android.com203.208.46.146 www.google.com 203.208.46.146 dl.google.com 203.2 ...
- UML学习笔记2
4.协作图 它跟顺序图区别:前者强调时间,后者强调空间.两者可以转换 5.状态图 主要用于时间建模 6.活动图 7.构件图
- Qt + FFmpeg 本地音频播放器
http://pan.baidu.com/s/1hqoYXrI
- Android 布局优化
转载自stormzhang的博客:http://stormzhang.com/android/2014/04/10/android-optimize-layout/ < include /> ...