Leetcode-203 Remove Linked List Elements
#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.
- * struct ListNode {
- * int val;
- * ListNode *next;
- * ListNode(int x) : val(x), next(NULL) {}
- * };
- */
- class Solution {
- public:
- ListNode* removeElements(ListNode* head, int val) {
- ListNode* p=head;
- ListNode* pre=new ListNode();
- pre->next=head;
- ListNode* ret=pre;
- while(p!=NULL)
- {
- if(p->val==val)
- {
- pre->next=p->next;
- }
- else
- {
- pre=pre->next;
- }
- p=p->next;
- }
- return ret->next;
- }
- };
Leetcode-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题要求 ...
- 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 移除链表元素
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 --& ...
- 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 --& ...
- 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 链表
去掉链表中相应的元素值 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next ...
- [leetcode]203. Remove Linked List Elements链表中删除节点
这道题很基础也很重要 重点就是设置超前节点 public ListNode removeElements(ListNode head, int val) { //超前节点 ListNode pre = ...
随机推荐
- 关于 tomcat nio connector, servlet 3.0 async, spring mvc async 的关系
tomcat 的 org.apache.coyote.http11.Http11NioProtocol Connector 是一个使用 Java NIO 实现的异步 accept 请求的 connec ...
- python 写文件,utf-8问题
写文件报数据. 同样的编码. 含中文字段的输出文件 编码为utf-8 无中文的却是asc import codecstxt = u”qwer”file=codecs.open(“test”,”w”,” ...
- 【Lua】Debian环境下openresty的安装
OpenResty (也称为 ngx_openresty)是一个全功能的 Web 应用服务器,它打包了标准的 Nginx 核心,很多的常用的第三方模块,以及它们的大多数依赖项. OpenResty 通 ...
- 咏南IOCP中间件支持海量并发方案(集群)
咏南IOCP中间件支持海量并发方案(集群) 支持D7~XE10.1.1开发 支持负载均衡,自动故障转移 可以在不停机的状态下,根据负载情况灵活增加中间件机器 中间件使用IOCP通信,单中间件支持并发数 ...
- 通过pycurl模块添加put和delete请求
原文链接: http://anupamshakya.blogspot.com/2013/07/implementation-of-put-and-delete-in.html
- Jquery点击发送按钮后,按钮文本倒计时
1.html代码 <input type="number" id="mobileNo" placeholder="请输入手机号" /& ...
- LeetCode:Permutations, Permutations II(求全排列)
Permutations Given a collection of numbers, return all possible permutations. For example, [1,2,3] h ...
- Windows Phone 8.1 新特性 - 控件之应用程序栏
2014年4月3日的微软Build 2014 大会上,Windows Phone 8.1 正式发布.相较于Windows Phone 8,不论从用户还是开发者的角度,都产生了很大的变化.接下来我们会用 ...
- Debian 8 最小化系统安装muduo
最近开始学习陈硕的muduo C++ Linux多线程网络库,首先当然是要安装.其间遇到过不少问题,最后不能说都解决了,只能说找到了一条不会遇到什么问题的路线.总结起来是两点: 注意各软件之间要版本匹 ...
- JS 将字符串转换成日期类型
将字符串形式的日期转换成日期对象 var strTime="2011-04-16"; //字符串日期格式 var date= new Date(Date.par ...