Leetcode-203 Remove Linked List Elements

时间:2022-05-10 07:53:44

#203.   Remove Linked List Elements

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

/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* removeElements(ListNode* head, int val) {
ListNode* p=head;
ListNode* pre=new ListNode();
pre->next=head;
ListNode* ret=pre; while(p!=NULL)
{
if(p->val==val)
{
pre->next=p->next;
}
else
{
pre=pre->next;
}
p=p->next;
}
return ret->next;
}
};

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 (移除链表中的项)

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

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

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

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

  5. (easy)LeetCode 203.Remove Linked List Elements

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

  6. Java [Leetcode 203]Remove Linked List Elements

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

  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 移除链表元素 C++/Java

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

  9. Leetcode 203 Remove Linked List Elements 链表

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

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

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

随机推荐

  1. POJ 2010

    Moo University - Financial Aid Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 4235   A ...

  2. WinForm控件使用文章收藏整理完成

    对C# WinForm开发系列收集的控件使用方面进行整理, 加入了一些文章, 不断补充充实, 完善这方面. 基础 - 常用控件 C# WinForm开发系列 - CheckBox/Button/Lab ...

  3. H1标签使用的七大注意事项

    H1标签使用的七大注意事项: 1 每个页面都应该有H1标签,H1标签是每个网页不可缺少的要素. 2 使用H1标签的内容应该简洁明了; 3 H1标签要尽量出现在源文件代码的开头的部分,这样可以让访问者和 ...

  4. zabbix discovery

    preface(见面礼): 仅扫tcp端口: netstat -tnlp|egrep -i "$1"

  5. FJ省队集训最终测试 T3

    思路:状态压缩dp,f[i][j[[k]代表i行j列这个格子,连续的状态为k,这个连续的状态是什么?就是下图 X格子代表我当前走到的地方,而这里的状态就是红色部分,也就是连续的一段n的状态,我们是分每 ...

  6. U盘读写速度测试

    1.ATTO Disk Benchmark    测U盘读写速度 ATTO Disk Benchmark 是一款简单易用的磁盘传输速率检测软件,可以用来检测硬盘.U盘.存储卡及其它可移动磁盘的读取及写 ...

  7. Java读取resource文件/路径的几种方式

    方式一: String fileName = this.getClass().getClassLoader().getResource("文件名").getPath();//获取文 ...

  8. 6_linux用户及权限(1)

    ------------用户管理: useradd,userdel,usermod,passwd,chsh,chfn,finger,id,chage组管理: groupadd,groupdel,gro ...

  9. ASP.NET Core使用TopShelf部署Windows服务

    asp.net core很大的方便了跨平台的开发者,linux的开发者可以使用apache和nginx来做反向代理,windows上可以用IIS进行反向代理. 反向代理可以提供很多特性,固然很好.但是 ...

  10. phpstudy的使用

    1.第一步是下载phpstudy,你可以百度去下载,也可以通过下面我分享的网盘下载 链接:https://pan.baidu.com/s/1E_CXIrKv1N-jrlA4KCovZA 密码:mkx9 ...