(easy)LeetCode 237.Delete Node in a Linked List
2015-07-31 18:02
507 查看
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
思想:将要删除节点的下一个节点的值赋给要删除的节点,删除要删除节点的下一节点即可。
代码如下:
运行结果:
Supposed the linked list is
1 -> 2 -> 3 -> 4and you are given the third node with value
3, the linked list should become
1 -> 2 -> 4after 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; } }
运行结果:
相关文章推荐
- win8.1 JMeter启动时显示Could not open/create prefs root node Software\JavaSoft\Prefs at root
- Node.js 使用 child_process 实现多进程
- suse10下nodejs安装时提示openssl not found的问题解决办法 1、首先确认openssl有没有安装,使用命令 openssl version 2、明明已经安装了openssl
- nodejs使用笔记
- nodejs 模块安装与使用
- MonoDevelop 常用设置和快捷键
- nodejs随记01
- nodejs安装express
- nodejs windows环境安装
- Delete Node in a Linked List Java LeetCode
- LeetCode_237 Delete Node in a Linked List
- Cannot delete .... . Name node is in safe mode
- hadoop启动后jps查看总是不显示namenode进程,然后重新格式化hdfs
- node-odata: ASP.NET WEB API OData的替代品
- VFS,super_block,inode,dentry—结构体图解
- [CareerCup] 4.2 Route between Two Nodes in Directed Graph 有向图中两点的路径
- java学习脚印:xml中空白文本结点(whitespace TextNode)处理及验证方法
- leetcode之路019 Remove Nth Node From End of List
- NodeJS + PhantomJS 抓取页面信息以及截图
- 利用nodejs+phantomjs+casperjs采集淘宝商品的价格