203. Remove Linked List Elements (List)
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* newHead = new ListNode();
newHead->next = head;
ListNode* pre = newHead;
ListNode* cur = head; while(cur){
if(cur->val == val){
pre->next = cur->next;
}
else{
pre = pre->next;
}
cur = cur->next;
}
return newHead->next;
}
};
203. Remove Linked List Elements (List)的更多相关文章
- 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题要求 ...
- 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 - LeetCode
Question 203. Remove Linked List Elements Solution 题目大意:从链表中删除给定的数 思路:遍历链表,如果该节点的值等于给的数就删除该节点,注意首节点 ...
- 【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* ...
- 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 -- ...
- 203. Remove Linked List Elements
Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...
- (easy)LeetCode 203.Remove Linked List Elements
Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...
- Java [Leetcode 203]Remove Linked List Elements
题目描述: Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> ...
- [LeetCode] 203. Remove Linked List Elements 解题思路
Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...
随机推荐
- 没有cv2.so文件
最近发现opencv安装的有问题,发现少了cv2.so文件,这个文件是给python的调度包. 查来查去,发现cmake的时候有这个: -- Found PythonInterp: /usr/bin/ ...
- 最详细安装Esxi
https://www.vmware.com/cn/products/vsphere-hypervisor.html Exsi 是一款虚拟化系统,与VMware,VirtualBox不同,它不需要安装 ...
- 机器学习进阶-直方图与傅里叶变换-图像直方图 1.cv2.calc(生成图像的像素频数分布(直方图))
1. cv2.calc([img], [0], mask, [256], [0, 256]) # 用于生成图像的频数直方图 参数说明: [img]表示输入的图片, [0]表示第几个通道, mask表 ...
- native.js 判断是否安装某app
例:是否安装微信 function isWeixin() { var UIApplication = plus.ios.importClass("UIApplication"); ...
- ACM__容器之vector
今天做题碰到了深搜的题,有一种存图方式需要用到vector,对vector不是很熟悉,回顾了一下 vector都知道是一个容器,但并不准确,它是一个多功能的能够操作多种数据结构和算法的模板类和函数库. ...
- 如何查看虚拟机的ip地址,以及如何给虚拟机配置静态ip
1 在命令行上敲ifconfig 如下图: 通过inet addr : 192.168.25.129就是你的虚拟机当前的ip 2. 我们一般在局域网内是通过dhcp协议向网关发送ip请求,因此获取的i ...
- How to Pronounce We’ll Contraction
How to Pronounce We’ll Contraction Share Tweet Share Tagged With: WILL Contractions There are severa ...
- ReactiveX 学习笔记(4)过滤数据流
Filtering Observables 本文主题为过滤 Observable 的操作符. 这里的 Observable 实质上是可观察的数据流. RxJava操作符(三)Filtering Deb ...
- jquery 初始化数据 添加html 第一次玩0.0
/** * Created by Eee_xiang on 2018/04/12. * 联动响应事件 */ (function () { $.linkEvent = function (options ...
- effective C++学习一(仅供个人学习记录,本文摘录effective C++)
条款 1:尽量用 const 和 inline 而不用#define #define ASPECT_RATIO 1.653 编译器会永远也看不到 ASPECT_RATIO 这个符号名,因为在源码进 ...