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 (在链表中删除一个点)的更多相关文章

  1. [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 ...

  2. [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 ...

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

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

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

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

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

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

  9. [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 ...

随机推荐

  1. 【Android开发】XML文件解析

    最近在做一个项目,涉及到XML文件的解析,废话不多说,如下: 读取 private ArrayList<Data> readXMLLocked() { File file = new Fi ...

  2. python生成动态个性二维码

    1 安装工具2 生成普通二维码3 带图片的二维码4 动态 GIF 二维码5 在Python程序中使用 一.安装 首先在python环境下运行, 打开cmd进入python27 进入scripts 然后 ...

  3. Slow HTTP Denial of Service Attack 漏洞解决办法

    编辑 删除 问题名称: Slow HTTP Denial of Service Attack 问题URL http://10.238.*.*:58*** 风险等级: 高 问题类型: 服务器配置类 漏洞 ...

  4. java设计模式之代理模式模式总结

    定义:代理模式这种设计模式是一种使用代理对象来执行目标对象的方法并在代理对象中增强目标对象方法的一种设计模式. 解读定义: 1.代理对象和目标对象有共同的接口: 2.使用代理对象执行目标对象中的方法: ...

  5. tomcat 访问IP直接访问项目

    apache-tomcat-7.0.52\conf下server.xml文件 <Connector connectionTimeout="20000" port=" ...

  6. (转)Eclipse在线配置Hibernate Tools

    http://blog.csdn.net/yerenyuan_pku/article/details/52733403 查看Eclipse版本 Eclipse针对程序开发有很多发行版本,除了开发语言的 ...

  7. MFC_2.2 编辑框和文本控件

    编辑框和文本控件 1.拖控件 2.绑定变量.用户名密码编辑框控件类型.取名字.用户协议用值类型,默认CString. 设置属性.用户类型.选择mustiline TRUE. AOTO HScroll ...

  8. 【转】Go语言入门教程(一)Linux下安装Go

    说明 系统是Ubuntu. 关于安装 下载安装包 当前官方下载地址是https://golang.org/dl/,如果不能访问,请自行FQ,FQ是技术工作者的必备技能. 安装 tar -xzvf go ...

  9. React-native SyntaxError: Unexpected token ...

    更新 node.js 版本到  v6.11.1. https://github.com/facebook/react-native/issues/15040

  10. 首次开通blog,以后会慢慢把oneNote和印象笔记的笔记转过来

    之前一直都是把笔记和经验写到OneNote上面,终于,OneNote无法同步了,转战blog吧,在这上面写一些笔记和一些技术,有空可以慢慢回顾一下.笔记这种东西,过一段时间再看就会有不同的感悟.