题目: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.

解法:(参考博客:http://www.cnblogs.com/tjuloading/p/4648652.html

将当前结点伪装成下一个结点,然后删除下一个结点即可。(真是太巧妙了,以前都没想到过这种删除方法)

/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
public class Solution {
public void deleteNode(ListNode node) {
node.val = node.next.val;
node.next = node.next.next;
}
}

LeetCode:237的更多相关文章

  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 to th ...

  4. Java实现 LeetCode 237 删除链表中的节点

    237. 删除链表中的节点 请编写一个函数,使其可以删除某个链表中给定的(非末尾)节点,你将只被给定要求被删除的节点. 现有一个链表 – head = [4,5,1,9],它可以表示为: 示例 1: ...

  5. Java for LeetCode 237 Delete Node in a Linked List

    Java实现如下: public class Solution { public void deleteNode(ListNode node) { if(node==null||node.next== ...

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

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

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

  9. leetCode:237 删除链表的结点

    删除链表的结点 编写一个函数,在给定单链表一个结点(非尾结点)的情况下,删除该结点. 假设该链表为1 -> 2 -> 3 -> 4 并且给定你链表中第三个值为3的节点,在调用你的函数 ...

随机推荐

  1. [Hibernate] - Study 1

    1)解压Hibernate,在eclipse中导入jar包,其中lib\required里的jar包是必需包括在里头的.这里用的是sql server,所以要导入sqljdbc4.jar 2)在src ...

  2. visibility和display的区别

    大多数人很容易将CSS属性display和visibility混淆,它们看似没有什么不同,其实它们的差别却是很大的. visibility属性用来确定元素是显示还是隐藏的,这用visibility=& ...

  3. idea系列新版注册模式

    http://idea.qinxi1992.cn/ 楼上被列入黑名单,用 http://114.215.133.70:41017/

  4. 推荐一个golang的json库

    生成json的库 https://github.com/bennyscetbun/jsongo https://github.com/donnie4w/json4g

  5. 黄聪:WebBrowser执行和安装jQuery脚本(IEBrowse)

    上一文章说明了如何让 js 脚本访问 .NET 中的类, 这次希望给大家说明一下在任意页面中安装 jQuery 脚本, 并操作页面上的元素. 其实在第一篇关于 IEBrowser 的文章当中, 已经有 ...

  6. SQL语言的三个分类:DDL、DML、DCL

    DML:数据操纵语言,主要是完成数据的新增,修改,删除和查询的操作. DDL:数据定义语言,主要是用来创建或修改表.视图.存储过程以及用户等. DCL:数据控制语言,是用来设置或更改数据库用户或角色权 ...

  7. ADO.NET(查询、属性扩展)

    一.ADO.NET 融合面向对象的查询语句 1.只查询一条数据 //数据访问中的select方法 public stu select(string xuehao) { stu s = null; cm ...

  8. group by 获取总记录数

    sql中有group buy 后如何获取总记录的条数,来生成分页 当然一般情况下我是不推荐这样的分页,如果你真的需要应该是你表结构设计有问题 1.适用于所有情况 $db = new PDO(DSN.. ...

  9. [复变函数]第05堂课 1.4 复球面与 $\infty$; 作业讲解; 2 解析函数 2.1 解析函数的概念与 Cauchy-Riemann 方程

    1. 复球面 大漠孤烟直, 长河落日圆. $$\bex \bbC\cong \bbS^2\bs \sed{N},\quad \bbC_\infty=\bbC\cup \sed{\infty}\mbox ...

  10. 发现木马C:\windows\system32\FastUserSwitchingCompatibilityex.dll

    而且用安全狗还隔离不了