Remove all elements from a linked list of integers that have value val.

Example

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】的更多相关文章

  1. 203. Remove Linked List Elements【easy】

    203. Remove Linked List Elements[easy] Remove all elements from a linked list of integers that have ...

  2. 203. Remove Linked List Elements【Easy】【未排序链表删除其中的给定值】

    Remove all elements from a linked list of integers that have value val. Example: Input: 1->2-> ...

  3. 466. Count Linked List Nodes【Naive】

    Count how many nodes in a linked list. Example Given 1->3->5, return 3. 解法一: /** * Definition ...

  4. 【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 ...

  5. 【LeetCode】203. Remove Linked List Elements

    Remove Linked List Elements Remove all elements from a linked list of integers that have value val. ...

  6. 【刷题-LeetCode】203. Remove Linked List Elements

    Remove Linked List Elements Remove all elements from a linked list of integers that have value *val* ...

  7. [LintCode] Remove Linked List Elements 移除链表元素

    Remove all elements from a linked list of integers that have value val. Have you met this question i ...

  8. Leetcode-203 Remove Linked List Elements

    #203.   Remove Linked List Elements Remove all elements from a linked list of integers that have val ...

  9. 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题要求 ...

随机推荐

  1. 数学图形(2.6)Satellit curve

    这曲线有点像鼓,绕在球上两头是开口的. #http://www.mathcurve.com/courbes3d/satellite/satellite.shtml vertices = t = to ...

  2. unexpected token: * 和 java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to 解决办法

    一.unexpected token: *  的解决办法 首先要搞清楚sql与hql的区别! sql操作的是数据库表,而hql操作的是对象! sql中“select * from table”,而hq ...

  3. Python基础(12)--模块

    本文地址:http://www.cnblogs.com/archimedes/p/python-modules.html,转载请注明源地址. 模块简介 如果你退出 Python 解释器重新进入,以前创 ...

  4. 飘逸的python - 不使用keyword,求和1+2+…+n

    依据题意,我们不能用到if/else/for/while等keyword. --------------思考中------------ 思路: 1.用递归实现循环 2.递归的终止条件不用if怎么推断呢 ...

  5. jvm分析备忘

    是什么 jps   查看所有的jvm进程,包括进程ID,进程启动的路径等等. jstack   观察jvm中当前所有线程的运行情况和线程当前状态. 系统崩溃了?如果java程序崩溃生成core文件,j ...

  6. iOS中使用iCloud一些须要注意的地方(Xcode7.2)

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 假设认为写的不好请多提意见,假设认为不错请多多支持点赞.谢谢! hopy ;) 在自己的App中怎样使用iCloud有非常多文章能够查阅,这里 ...

  7. myDate97 设置开始时间和结束时间

      myDate97 设置开始时间和结束时间 CreationTime--2018年8月28日16点46分 Author:Marydon 1.简单示例 第一步:引入My97DatePicker/Wda ...

  8. window 10下 MySql5.7压缩包安装

    步骤如下: 1. 解压缩到某位置, 在其根目录下 新建data空目录, 新建my.ini,内容如下: [mysql] default-character-set=utf8 [mysqld] port ...

  9. OSSSME - 开源软件助力中小企业发展

    怀揣着为中小企业量身定做一整套开源软件解决方案的梦想开始了一个网站的搭建.http://osssme.org/ [2013-8-2] 由于同时更新2个站点的信息比较繁琐,今后所有和iDempiere. ...

  10. MySQL学习记录一

    1.MySQL join操作 left join以左表为基础,其记录会全部表示出来,而右表只显示满足搜索条件的记录.right join以右表为基础,其记录会全部显示出来,而左表只显示满足搜索条件的记 ...