题目: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. VBA 插入一行保留样式

    Rows(processingRow).Insert ' 在指定的行数processingRow处插入一行 Rows(processingRow - 1).Select ' 选择上一行的整行 Sele ...

  2. PHPNow升级PHP版本为5.3.5的方法

    在WIN上有时候需要测试一些PHP程序,又不会自行独立配置环境,那么PHPNow是非常好的选择,这篇文章主要为大家分享下如果将phpnow的php版本升级为5.3.5   在WIN上有时候需要测试一些 ...

  3. Windows2012修改光驱盘符

    1.输入diskmgmt.msc打开磁盘管理器 2.找到需要修改的盘符,右键点击修改盘符

  4. Linux下SSH的Log文件路径

    Redhat or Fedora Core: /var/log/secure # Mandrake, FreeBSD or OpenBSD: /var/log/auth.log # SuSE: /va ...

  5. MyEclipse 设置注释

    MyEclipse设置注释的方法 windows-Preferences-(弹出窗口) 单击[Edit]后弹出编辑窗口,然后进行编辑

  6. 黄聪:jquery mobile通过a标签页面跳转后,样式丢失、js失效的解决方法

    问题描述: 用ajax跳转的时候,从a.html跳转到b.html后,b.html的css以及js都失效了. 解决办法1: 将所有的css以及js全部放在div内. 原理: 由于jqm的ajax跳转的 ...

  7. sbt设置

    配置中央仓库 vim ~/.sbt/repositories [repositories] local osc: http://maven.oschina.net/content/groups/pub ...

  8. BIP_开发案例09_结合JavaCP通过BIP API输出报表dataprocess / rtfprocess / foprocess(案例)

    20150814 Created By BaoXinjian

  9. Web Penetration Testing 渗透 通信信息安全

    参考 http://download.csdn.net/detail/jason571/8146587 一.操作系统原理,JavaScript,http/https的运行原理,Ajax,SQL等技术基 ...

  10. 图片_ _ Bitmap_Drawable_Image?

    ===== 2 ==== 1 b.读取res/drawable目录下的 png或者bmp Resources r = this.getContext().getResources(); //以数据流的 ...