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题要求 ...
随机推荐
- 如何将js的object对象传到后台--->JavaScript之对象序列化
一个问题:前台js如何传Object对象到后台哪 百度了半天,结果如下:只需要将object对象转化成json格式 然后传到后台 再在后台解析json字符串即可 那么问题来了: Object如何转 ...
- Win10系统中新增的快捷键,做个记录
Win10系统中新增的快捷键,做个记录 1.Win+Q或者Win+S 打开下面搜索框 2.Win+T 切换任务栏上程序: 3.Win+ ...
- 【干货合集】Docker快速入门与进阶
收录待用,修改转载已取得腾讯云授权 Docker 在众多技术中,绝对是当红炸子鸡.这年头,如果你不懂一点容器,不学一些Docker,还怎么出去跟人炫耀技术? Docker 也是云计算技术中较为热门的一 ...
- 如何修改Git commit的信息
原文地址: http://xiguada.org/change-git-commit-message Git cimmit信息push后,如何修改,amend可以修改最后一次commit信息,但对 ...
- 使用BeyondCompare比较文件夹下的文件时,相同的文件内容,但显示为不相同
主要原因是: 两个文件行尾标题不一致而导致的,一个是PC,一个是Unix 解决办法: 随便比较文件夹中的两个文件,点击规则,去掉比较行尾(pc/mac/unix)选项,点击确认,回到文件夹比较界面,刷 ...
- 分布式系统漫谈一 —— Google三驾马车: GFS,mapreduce,Bigtable
分布式系统学习必读文章!!!! 原文:http://blog.sina.com.cn/s/blog_4ed630e801000bi3.html 分布式系统漫谈一 —— Google三驾马车: GFS, ...
- 【Project Euler 1】Multiples of 3 and 5
题目要求是: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and ...
- html5图像、图片处理【转】
本文主题 情人节在网上看到国外JS牛人利用HTML5技术实现的一朵玫瑰花,深切的感受到HTML5技术的强大.本着学习的态度看了一下那朵玫瑰花的源代码,其中用到的HTML5技术是canvas标签,于是灵 ...
- AsyncTask doinbackground onProgressUpdate onCancelled onPostExecute的基本使用
对于异步操作的原理我就不讲了.在这我着重讲怎么使用异步操作的doinbackground onProgressUpdate onCancelled onPostExecute这四个方法 doinbac ...
- AjaxAnyWhere 实现页面局部刷新,局部分页
这个比較jquery.单纯ajax异步简单多了.不多说了直接上代码. 须要引入:ajaxanywhere-1.2.1.jar (最新)和 /ajaxAnyWhereDemo/WebRoot/js/aa ...