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) {
ListNode nextNode=node.next;
node.val=nextNode.val;
node.next=nextNode.next; }
}

  运行结果:

(easy)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 to th ...

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

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

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

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

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

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

随机推荐

  1. Dom之标签增删操作

    dom操作:THML新增子标签 a标签(appendChild) <!DOCTYPE html><html lang="en"><head> & ...

  2. TKinter布局之pack

    pack布局非常简单,不用做过多的设置,直接使用一个 pack 函数就可以了. 1.我们使用 pack 函数的时候,默认先使用的放到上面,然 后 依次向下排,它会给我们的组件一个自认为合适的位置 和大 ...

  3. Android App监听软键盘按键的三种方式

    前言:   我们在android手机上面有时候会遇到监听手机软键盘按键的时候,例如:我们在浏览器输入url完毕后可以点击软键盘右下角的“GO”按键加载url页面:在点击搜索框的时候,点击右下角的sea ...

  4. C# 如何通过拼接XML调用存储过程来优化系统性能

    平常新增多条记录,需要多次访问数据库,这样会影响性能:如果把新增的数据拼接成XML形式,作为参数传给存储过程来处理,这只访问数据库一次,执行速度会快很多. 1.C#代码如下:XML拼接的字段不能出现& ...

  5. eclipse项目持续报红解决

    1.tomcat 同步,点击publish: 2.clear项目 3.项目报红,Maven --->UpdateProject 4.pom.xml需要更新,下载最新jar包,附图:

  6. 将Excel数据导入Oracle中

    第一步:修改Excel 1.将Excel的表头修改为目标数据库中表的字段名 2.去重(如果有需要的话) 删除Excel表中的重复数据: 选择去重的列: 删除成功后提示: 第二步:将修改后的Excel另 ...

  7. 阿里云Mysql重置密码

    1.关闭mysql服务 # service mysql stop 如果提示mysql: unrecognized service这样的错误提示. 先查看查找mysql.server,使用:find / ...

  8. 程序员书单_J2EE专题

    Enterprise JavaBeans 3.0中文版(第5版) http://download.csdn.net/detail/shenzhq1980/9104015 J2EE设计模式 http:/ ...

  9. 程序员书单_UML篇

    UML基础与Rose建模教程 http://download.csdn.net/detail/shenzhq1980/9076199 UML和模式应用1 Applying UML and Patter ...

  10. jquery radio的取值 radio的选中 radio的重置

    radio 按钮组, name=”sex”. <input type="radio" name="sex" value="Male"& ...