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

解题思路:

JAVA实现如下:

    public ListNode removeElements(ListNode head, int val) {
ListNode root=new ListNode(val+1),temp=root;
root.next=head;
while(temp.next!=null){
if(temp.next.val==val)
temp.next=temp.next.next;
else temp=temp.next;
}
return root.next;
}

Java for LeetCode 203 Remove Linked List Elements的更多相关文章

  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. LeetCode 203. Remove Linked List Elements 移除链表元素 C++/Java

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

  3. Java [Leetcode 203]Remove Linked List Elements

    题目描述: Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> ...

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

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

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

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

  6. (easy)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 链表

    去掉链表中相应的元素值 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next ...

  9. [leetcode]203. Remove Linked List Elements链表中删除节点

    这道题很基础也很重要 重点就是设置超前节点 public ListNode removeElements(ListNode head, int val) { //超前节点 ListNode pre = ...

随机推荐

  1. Shell good example

    (1) Source code #! /bin/bash reference ()     {     pa=\$"$1"     echo $pa     x=`eval &qu ...

  2. 【HDU 2203】亲和串

    题 题意 给你一个字符串s1,字符串s2,s1循环移位,使s2包含在s1中,则s2 是s1的亲和串 分析 把s1自身复制一遍接在后面. 方法一: 用strstr函数. 方法二: KMP算法. 方法三: ...

  3. yii2图片上传

    yii2利用自带UploadedFile上传图片 public static function uploadFile($name) { $uploadedFile = UploadedFile::ge ...

  4. 使用属性表:VS2013上配置OpenCV

    以前,windows下配置OpenCV一直不太方便:总是要手动添加lib,添加include,还要配置PATH使得程序运行时候能找到dll文件. 每次新建一个使用OpenCV的工程都要手动添加,很麻烦 ...

  5. opencv笔记3:trackbar简单使用

    time:2015年 10月 03日 星期六 13:54:17 CST # opencv笔记3:trackbar简单使用 当需要测试某变量的一系列取值取值会产生什么结果时,适合用trackbar.看起 ...

  6. 【BZOJ-2588】Count on a tree 主席树 + 倍增

    2588: Spoj 10628. Count on a tree Time Limit: 12 Sec  Memory Limit: 128 MBSubmit: 3749  Solved: 873[ ...

  7. a[1000][1000]程序崩溃

    1000 * 1000是大于65536的.如果不是需求需要,没必要开辟如此之多的空间.因为这些空间实在栈上申请的(如果是局部变量),栈的空间是有限的并且是宝贵的,所以呢,开辟太多的空间而不适用很可能会 ...

  8. 【Beta阶段】发布说明

    在经历Beta阶段紧张的开发后,本次Beta阶段取得的成果虽然不如Alpha阶段多,但是也算是做到了稳中求进,一共预想了三个feature,最终做出了预想的两个feature. 新功能说明 新的主页: ...

  9. 如何使用网盘托管git项目

    话说近年来git已经成为项目源代码管理的标准工具,有不少免费托管网站可供使用,详情参考这篇文章: http://www.cnblogs.com/zdz8207/archive/2012/05/20/2 ...

  10. win32控制台消息机制

    源码: #include<windows.h>HANDLE hInput; /* 获取标准输入设备句柄 */INPUT_RECORD inRec;/* 返回数据记录 */DWORD num ...