Remove Linked List Elements
2015-09-11 22:57
246 查看
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
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 dummy = new ListNode(0); dummy.next = head; head = dummy; while(head != null){ while(head.next != null && head.next.val == val){ head.next = head.next.next; } head = head.next; } return dummy.next; } }
相关文章推荐
- 【一些事晚报】iPhone 6s/Plus港版比内地最多便宜1128元
- 数据可视化工具
- initwithcoder和 initwithframe
- Things That Cannnot Change(Android里不能改变的东西)
- Android中事件传递机制的总结
- 第三讲:C++基础语法 & 创建第一个场景 ------学习笔记
- Activity的四种启动模式和onNewIntent()
- 利用System.in.read() 函数从键盘读入一系列字符
- HeapAlloc 和 GlobalAlloc 以及 VirtualAlloc 三者之间的关系
- 两个队列实现一个栈
- page-rank计算问题
- DICOM:DICOM中文版开源书籍协同编辑之“Github Pull Requests”
- LNMP系列——Mysql生产环境配置
- OC直接打印数组,数组元素显示中文的问题
- java子父类的加载顺序
- PHP中一些有用的函数
- JavaScript权威设计--JavaScript表达式与运算符,语句(简要学习笔记六)
- 为什么使用boost编程
- LNMP系列——常用的linux命令
- ios设计模式——生成器模式