LintCode-- Remove Linked List Elements
Remove all elements from a linked list of integers that have valueval
.
Given 1->2->3->3->4->5->3
, val = 3, you should return the list as1->2->4->5
/*** Definition for singly-linked list.* public class ListNode {* int val;* ListNode next;* ListNode(int x) { val = x; }* }*/
public class Solution {/*** @param head a ListNode* @param val an integer* @return a ListNode*/public ListNode removeElements(ListNode head, int val) {// Write your code hereif (head == null) {return head;}ListNode cur = head;ListNode returnHead = new ListNode(-1);returnHead.next = cur;ListNode pre = returnHead;while (cur != null) {if (cur.val == val) {pre.next = cur.next;} else {pre = pre.next;}cur = cur.next;}return returnHead.next;}
}
LintCode-- Remove Linked List Elements相关推荐
- leetcode 203 Remove Linked List Elements
Remove all elements from a linked list of integers that have valueval. Example Given: 1 --> 2 ...
- (LeetCode 203)Remove Linked List Elements
Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 -- ...
- 【leetcode】Remove Linked List Elements(easy)
Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 -- ...
- Remove Linked List Elements
Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 -- ...
- [LeetCode]Remove Linked List Elements
题目描述:(链接) Remove all elements from a linked list of integers that have value val. Example Given: 1 - ...
- Leet Code OJ 203. Remove Linked List Elements [Difficulty: Easy]
题目: Remove all elements from a linked list of integers that have value val. Example Given: 1 –> 2 ...
- [LeetCode-JAVA] Remove Linked List Elements
题目: Remove all elements from a linked list of integers that have value val. Example Given: 1 --> ...
- LeetCode 203. Remove Linked List Elements
题目: Remove all elements from a linked list of integers that have value val. Example Given: 1 –> 2 ...
- C#LeetCode刷题之#203-删除链表中的节点(Remove Linked List Elements)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3826 访问. 删除链表中等于给定值 val 的所有节点. 输入: ...
- leetcode 203. Remove Linked List Elements(链表)
Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 -- ...
最新文章
- [转载]分享WCF聊天程序--WCFChat
- [bzoj 2456]mode
- FPGA内部电源管理详解
- c语言中c为字符型便量,c='97'是否正确,C语言判断题Word版
- mysql group by 集合_MySQL高级查询之与Group By集合使用介绍
- QT 中QPainter绘制文字、图片
- 1008. Elevator (20)
- flex布局导致拉伸的问题
- CF558E-A Simple Task-线段树+计数排序
- 小车启动预热是原地预热,还是慢慢开动预热,哪种方式比较好?
- java版AES加密算法实现
- 联想 缺少计算机所需的介质驱动程序,联想笔记本缺少驱动应该怎么办
- spring cloud微服务(二)euraka服务消费者
- torch.optim.SGD参数详解(除nesterov)
- 一脸懵逼搭建Zookeeper分布式集群
- ArcGIS Runtime for Android天地图底图及TPK数据包放大后数据不显示问题
- 谷歌服务组件安装简介
- 斑马Zebra LP2844 打印机驱动
- 凸包与Graham扫描法求凸包
- HDLBits问题--Lemmings
热门文章
- java第一章_java 第一章
- php双线切换线路,双线路策略路由和脚本备份切换
- python中文文本处理_python简单文本处理的方法
- [设计模式-结构型]桥接(Bridge )
- 自己动手写Docker系列 -- 6.3 手动配置容器网络(下)
- python如何输入多行数据合并_Python如何将多行数据合并成一行|python如何实现excle数据合并...
- 作为参数给后端为空_后端 API 接口文档 Swagger 使用指南
- 火狐浏览器允许ajax,ajax如何解决火狐浏览器或其它非ie浏览器的兼容性问题
- 计算机个人培训终结,计算机一级培训个人工作总结
- Dropping tests