题目描述:

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.

解题思路:

链表的常见操作。

代码如下:

/**
* 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) {
if(node == null)
return;
node.val = node.next.val;
node.next = node.next.next;
}
}

  

Java [Leetcode 273]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 删除链表结点(只给定要删除的结点) C++/Java

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

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

随机推荐

  1. python 实现文件批量拷贝

    场景:某个文件夹下面包含数量巨大的文件,需求需要将这些文件按组(比如5000个一组)存放到不同的目录中去. # Filename: CopyFiles.py import os import os.p ...

  2. 程序使用嵌套的for循环找出2〜100中的素数

    #import <Foundation/Foundation.h> int main () { /* local variable definition */ int i, j; ; i& ...

  3. Ubuntu下Sublime Text 3无法输入中文的解决方案

    1. 保存下面的代码到文件sublime_imfix.c中: /* * sublime-imfix.c * Use LD_PRELOAD to interpose some function to f ...

  4. C#基础及记忆概念

    在C#中,你给一个方法传输值类型参数时,实际上是使用的这个参数的一个副本,就是将原来的变量复制一份,然后传给一个方法,让其进行操作.所以在方法内部对参数的修改等不会对原来的参数造成影响(这个其实就是值 ...

  5. Xcode文档下载与安装路径

    https://developer.apple.com/library/downloads/docset-index.dvtdownloadableindex ~/Library/Developer/ ...

  6. poi导出到excel步骤分析

    在没用过poi之前感觉poi是很高大上的样子, 项目中用了发现poi的代码重复性很高类似于jdbc的模板代码, 项目中如果大量使用最好封装起来; 总结一下归结为6步 1 打开或新创建一个工作薄(使用H ...

  7. shell复习笔记----命令与参数

    shell最基本的工作就是执行命令. 每键入一道命令, shell 就会执行. $cd work;ls -l whizprog.c 首先:格式很简单,以空白(Space 键或者 Tab键)隔开命令行中 ...

  8. WCF获取客户端IP和端口

    //提供方法执行的上下文环境 OperationContext context = OperationContext.Current; //获取传进的消息属性 MessageProperties pr ...

  9. [转载]jquery cookie的用法

    原文地址:http://www.cnblogs.com/qiantuwuliang/archive/2009/07/19/1526663.html jQuery cookie是个很好的cookie插件 ...

  10. 团体程序设计天梯赛-练习集L1-003. 个位数统计

    L1-003. 个位数统计 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定一个k位整数N = dk-1*10k-1 + . ...