Leetcode 203 Remove Linked List Elements 链表
去掉链表中相应的元素值
/**
* 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) {
if(!head) return NULL;
ListNode* now = head;
for(;now->next ;){
if(now->next->val == val){
ListNode* next = now->next;
now->next = next->next;
delete next;
}
else now = now->next;
}
if(head->val == val) {
ListNode* t = head;
head = head->next;
delete t;
}
return head;
}
};
Leetcode 203 Remove Linked List Elements 链表的更多相关文章
- [leetcode]203. Remove Linked List Elements链表中删除节点
这道题很基础也很重要 重点就是设置超前节点 public ListNode removeElements(ListNode head, int val) { //超前节点 ListNode pre = ...
- 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题要求 ...
- LeetCode 203. Remove Linked List Elements (移除链表中的项)
Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...
- [LeetCode] 203. Remove Linked List Elements 移除链表元素
Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...
- LeetCode 203. Remove Linked List Elements 移除链表元素 C++/Java
Remove all elements from a linked list of integers that have value val. Example: Input: ->->-& ...
- Java [Leetcode 203]Remove Linked List Elements
题目描述: Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> ...
- 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 -- ...
- (easy)LeetCode 203.Remove Linked List Elements
Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...
- [LeetCode] 203. Remove Linked List Elements 解题思路
Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...
随机推荐
- java多线程学习-ThreadLocal
为了凑字,把oracle文档里介绍ThreadLocal抄过来 public class ThreadLocal<T> extends Object This class provides ...
- 剑指offer题目61-67
面试题61:把二叉树打印成多行 public class Solution { public ArrayList<ArrayList<Integer> > Print(Tree ...
- ng-bind,ng-cloak优化数据显示
<div>{{text}}</div> 当我们使用angular在页面中有取值的时候,如果出现网络加载慢的问题,可能会在页面上出现{{text}}这种不好的体验,那么angul ...
- 咏南中间件+开发框架支持最新的DELPHI XE10.1(BERLIN) UPDATE1
咏南中间件+开发框架支持最新的DELPHI XE10.1(BERLIN) UPDATE1 购买提供:中间件源码,价格十分优惠!有意者请向本人索取演示程序! 附带福利(赠送): CS开发框架源码BS开发 ...
- Maven学习之 Settings
虽然天天在用,但是没有系统的学习过,总觉得别扭. 只能用于Java项目. 约定: repository 翻译成 仓库 build 翻译成 构建 build system 翻译成 构建系统 build ...
- Ceph分层存储分析
最近弄Ceph集群考虑要不要加入分层存储 因此花了点时间研究了下 1,首先肯定要弄清Ceph分层存储的结构 ,结构图大概就是下图所示 缓存层(A cache tier)为Ceph客户端提供更好的I/O ...
- DataTime格式化大全(转载)
//c datetime 格式化 DateTime dt = DateTime.Now; Label1.Text = dt.ToString();//2005-11-5 13:21:25 Label2 ...
- EF常用查询写法
1.var list = from category in context.category join commodity in context.commodity on category.id eq ...
- jsp_包含指令
1.静态包含: <%@ include file="被包含的文件的路径"%> 2.动态包含: 不传递参数:<jsp:include page="{要包含 ...
- 6.3 Android Framework
Android的四层架构分别为Linux2.6内核层,核心库层,应用框架层,应用层.Framework层为我们开发应用程序提供了非常多的API,满足我们业务上的需求.(Android是基于Linux内 ...