452. Remove Linked List Elements【Naive】
Remove all elements from a linked list of integers that have value val.
Given 1->2->3->3->4->5->3, val = 3, you should return the list as 1->2->4->5
解法一:
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
/**
* @param head a ListNode
* @param val an integer
* @return a ListNode
*/
ListNode *removeElements(ListNode *head, int val) {
ListNode * dummy = new ListNode(-);
dummy->next = head;
head = dummy; while (head->next != NULL) {
if (head->next->val == val) {
head->next = head->next->next;
continue;
} head = head->next;
} return dummy->next;
}
};
452. Remove Linked List Elements【Naive】的更多相关文章
- 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【Easy】【未排序链表删除其中的给定值】
Remove all elements from a linked list of integers that have value val. Example: Input: 1->2-> ...
- 466. Count Linked List Nodes【Naive】
Count how many nodes in a linked list. Example Given 1->3->5, return 3. 解法一: /** * Definition ...
- 【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
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* ...
- [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 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题要求 ...
随机推荐
- 一个 forceLayout() 和 requestLayout() 的测试
两个view: 一个是系统默认的FrameLayout, A 一个是自己自定义的MyView extends View,重载了onMeasure函数(): B @Override protected ...
- WPF性能调试系列 – 应用程序时间线
WPF性能调试系列文章: WPF页面渲染优化:Application Timeline WPF页面业务加载优化:Ants Performance Profiler WPF内存优化:Ants Memor ...
- SRM 212 Div II Level One: YahtzeeScore
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=1692&rd=5858 比较简单. 代码如下: #inc ...
- Mysql优化与使用集锦
MyISAM的读性能是比Innodb强 MyISAM的索引和数据是分开的,并且索引是有压缩的 Innodb是索引和数据是紧密捆绑的,没有使用压缩从而会造成Innodb比MyISAM体积庞大不小 MyI ...
- css hack 和问题
浏览器特定的选择 当你想改变一个样式在一个浏览器而不是其他这些选择是非常有用的. IE 6及以下 * html {} IE 7及以下 *:first-child+html {} * htm ...
- java学习笔记11--集合总结
java学习笔记系列: java学习笔记10--泛型总结 java学习笔记9--内部类总结 java学习笔记8--接口总结 java学习笔记7--抽象类与抽象方法 java学习笔记6--类的继承.Ob ...
- Woocommerce 分类下的产品如何使用ID号来作为默认排序字段
在给一个客户开发网店系统时使用了WordPress系统的Woocommerce插件 WordPress版本:3.8 Woocommerce版本:2.0.20 如果没有指定排序规则(指定的字段),则Wo ...
- 基于java语言的给cube添加custom view来实现权限控制
今天是农历2014年的最后一个工作日了,在这里提前祝大家新年快乐.羊年大吉!当然本人今天也拿出来点儿真东西,做为献给大家的新年礼物,依次共勉. 下文主要讲述的是使用Java代码来完成对cube基于部门 ...
- 配置文件格式用哪个?文件夹+纯文本文件,XML,SQLite
稍具规模的软件都会须要一个配置文件来支持软件的执行.眼下常见的配置文件格式有纯文本.XML.SQLite.自己定义二进制格式,怎样进行选择呢? 1 纯文本--永远不会失效的文件格式 文本化是传统Uni ...
- The application is in break mode
在安装使用Visual Studio 2017后,当代码出现异常的时候,它没有调到代码出错的地方,显示了下图.. 解决办法:打开 Debug——>Options——>,勾上 Use Man ...