Question

203. Remove Linked List Elements

Solution

题目大意:从链表中删除给定的数

思路:遍历链表,如果该节点的值等于给的数就删除该节点,注意首节点

Java实现:

public ListNode removeElements(ListNode head, int val) {
ListNode cur = head; while (cur != null) {
if (cur.next != null && cur.next.val == val) {
ListNode tmp = cur.next.next;
cur.next = tmp;
} else {
cur = cur.next;
}
}
return (head != null && head.val == val) ? head.next : head;
}

203. Remove Linked List Elements - LeetCode的更多相关文章

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

  2. 203. Remove Linked List Elements【easy】

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

  3. 【LeetCode】203. Remove Linked List Elements

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

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

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

  5. 【一天一道Leetcode】#203.Remove Linked List Elements

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 我的个人博客已创建,欢迎大家持续关注! 一天一道le ...

  6. LeetCode 203. Remove Linked List Elements (移除链表中的项)

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

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

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

  8. 【LeetCode】203. Remove Linked List Elements 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 递归 日期 题目地址:https://lee ...

  9. 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 -- ...

随机推荐

  1. ubuntu sublime text3 python 配置 sublime text3 python 配置

    ubuntu sublime text3 python 配置     1.安装sublime text 3 安装过程非常简单,在terminal中输入: sudo add-apt-repository ...

  2. Python中的numpy库介绍!

    转自:https://blog.csdn.net/codedz/article/details/82869370 机器学习算法中大部分都是调用Numpy库来完成基础数值计算的.安装方法: pip3 i ...

  3. visio2019专业版激活码

    这里面有    :  最新Project2019+ Visio2019专业增强版和专业版永久激活密钥分享 (weibo.com)

  4. number(10,6)正则表达式

    /**     * 判断number(10,6)     * @param dateStr     * @return     */    public boolean isNumJW(String ...

  5. Python入门-系统模块time

    1.time模块 时间戳:1970年,1月1日开始时间元祖:包含日期,时间,保存日期结构的元祖对象格式化时间日期:按照指定的标记进行格式化处理 时间戳 import time time_num = t ...

  6. Struts2封装获取表单数据方式

    一.属性封装 1.创建User实体类` package cn.entity; public class User { private String username; private String p ...

  7. 自己写一个简单的LinkedList

    单链表 推荐阅读:https://www.cnblogs.com/zwtblog/tag/源码/ 哨兵节点: 哨兵节点在树和链表中被广泛用作伪头.伪尾等,通常不保存任何数据. 我们将使用伪头来简化我们 ...

  8. 挖矿病毒分析(centos7)

    因为我在工作的时候被各种挖矿病毒搞过几次,所以在这里整理下我遇到的病毒以及大神们的解决方案. 服务器中挖矿病毒后,最基本的一个特征就是CPU使用率瞬间飙升,此时可以通过top命令进行查看,确认是否有异 ...

  9. 一文搞懂MySQL事务的隔离性如何实现|MVCC

    关注公众号[程序员白泽],带你走进一个不一样的程序员/学生党 前言 MySQL有ACID四大特性,本文着重讲解MySQL不同事务之间的隔离性的概念,以及MySQL如何实现隔离性.下面先罗列一下MySQ ...

  10. JavaScript学习总结5-作用域

    由于所有的全局变量都会绑定到window上,如果不同的JS文件,使用了相同的全局变量,会造成冲突,可以把自己的代码全部放入及定义的唯一空间中,减少全局命名冲突问题