LeetCode 237. Delete Node in a Linked List (在链表中删除一个点)
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.
Supposed the linked list is 1 -> 2 -> 3 -> 4
and you are given the third node with value 3
, the linked list should become 1 -> 2 -> 4
after calling your function.
题目标签:Linked List
题目给了我们一个点,让我们在链表中删除这个点。
一般来说,要删除一个点,首先想到的是 把这个点的前面一个点 直接 链接到 这个点的 后面一个点 就可以了。
但是这一题只给了我们要删除的这个点(不会是最后一个点),所以回不到上一个点。
只要改变一下想法,用下一个点的val 复制到这一个点就可以了,然后把这一个点 链接到 下下个点就可以了。
Java Solution:
Runtime beats 9.42%
完成日期:06/12/2017
关键词:singly-linked list
关键点:把下一个点的val 复制到这一个点
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution
{
public void deleteNode(ListNode node)
{
// copy next node val into this node, then link this node to next next node
ListNode nextNode = node.next;
node.val = nextNode.val;
node.next = nextNode.next; nextNode.next = null; // unlink nextNode to null }
}
参考资料:N/A
LeetCode 题目列表 - LeetCode Questions List
题目来源:https://leetcode.com/
LeetCode 237. Delete Node in a Linked List (在链表中删除一个点)的更多相关文章
- [LeetCode] 237. Delete Node in a Linked List 解题思路
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
- [LeetCode] 237. Delete Node in a Linked List 删除链表的节点
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
- LeetCode 237 Delete Node in a Linked List 解题报告
题目要求 Write a function to delete a node (except the tail) in a singly linked list, given only access ...
- (easy)LeetCode 237.Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
- leetcode 237 Delete Node in a Linked List python
题目: Write a function to delete a node (except the tail) in a singly linked list, given only access t ...
- 17.leetcode 237. Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
- [Leetcode]237. Delete Node in a Linked List -David_Lin
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
- LeetCode 237. Delete Node in a Linked List 删除链表结点(只给定要删除的结点) C++/Java
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
- [LeetCode] 237. Delete Node in a Linked List_Easy tag: Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
随机推荐
- 用纯函数式思维在Java8下写的一段奇葩程序
首先说一下什么是纯函数式.在我的理解,"纯函数式"用一句话就可以描述:Anything is value.--我的理解不一定准确,但我就是这么理解的. 就是所有的东西都是值--没有 ...
- golang 自定义time.Time json输出格式
工作中使用golang时,遇到了一个问题.声明的struct含time.Time类型.使用json格式化struct时,time.Time被格式化成”2006-01-02T15:04:05.99999 ...
- jquery.ajax之beforeSend方法使用介绍
常见的一种效果,在用ajax请求时,没有返回前会出现前出现一个转动的loading小图标或者“内容加载中..”,用来告知用户正在请求数据.这个就可以用beforeSend方法来实现. 下载demo:a ...
- CAD从二制流数据中加载图形(com接口Delphi语言)
主要用到函数说明: _DMxDrawX::ReadBinStream 从二制流数据中加载图形,详细说明如下: 参数 说明 VARIANT varBinArray 二制流数据,是个byte数组 BSTR ...
- ThinkPHP---案例1登录登出和添加部门
配置文件分3类:系统配置文件,分组配置文件,应用配置文件 ①系统配置文件ThinkPHP/Conf/convention.php: ②分组 / 模块 /平台配置文件Home/Conf/config.p ...
- <MyBatis>入门八 工作原理
1.获取sqlSessionFactory对象 首先拿到全局配置文件的流对象 创建SqlSessionFactoryBuilder对象,并调用build方法,把流传进去 build方法 创建一个XML ...
- 关于Linux字符集的查看及修改
一·查看字符集 字符集在系统中体现形式是一个环境变量,其查看当前终端使用字符集的方式可以有以下几种方式: 1.[root@ ~]# echo $LANG en_US.UTF-8 ...
- 18年多校-1002 Balanced Sequence
>>点击进入原题测试<< 思路:自己写没写出来,想不通该怎么排序好,看了杜神代码后补题A掉的.重新理解了一下优先队列中重载小于号的含义,这里记录一下这种排序方式. #inclu ...
- Codeforces 990D - Graph And Its Complement
传送门:http://codeforces.com/contest/990/problem/D 这是一个构造问题. 构造一张n阶简单无向图G,使得其连通分支个数为a,且其补图的连通分支个数为b. 对于 ...
- 【Codeforces 300C】Beautiful Numbers
[链接] 我是链接,点我呀:) [题意] 让你找到长度为n的数字 这个数字只由a或者b组成 且这n个数码的和也是由a或者b组成的 求出满足这样要求的数字的个数 [题解] 枚举答案数字中b的个数为y,那 ...