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 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的更多相关文章
- [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 ...
- 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 ...
- [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 ...
- Java实现 LeetCode 237 删除链表中的节点
237. 删除链表中的节点 请编写一个函数,使其可以删除某个链表中给定的(非末尾)节点,你将只被给定要求被删除的节点. 现有一个链表 – head = [4,5,1,9],它可以表示为: 示例 1: ...
- Java for LeetCode 237 Delete Node in a Linked List
Java实现如下: public class Solution { public void deleteNode(ListNode node) { if(node==null||node.next== ...
- (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 ...
- 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 ...
- 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 ...
- leetCode:237 删除链表的结点
删除链表的结点 编写一个函数,在给定单链表一个结点(非尾结点)的情况下,删除该结点. 假设该链表为1 -> 2 -> 3 -> 4 并且给定你链表中第三个值为3的节点,在调用你的函数 ...
随机推荐
- 深入了解iPad上的MouseEvent【转】
iPad上没有鼠标,所以手指在触发触摸事件(TouchEvent)的时候,系统也会产生出模拟的鼠标事件(MouseEvent). 这对于普通网页的浏览需求而言,基本可以做到与PC端浏览器无明显 ...
- 【FreeMaker】FreeMaker学习-基础
转载请标明出处:http://www.cnblogs.com/ssslinppp 阅读目录 -04-08 08:08:08 Pacific Daylight Time Tue, Apr 8, '03 ...
- 黄聪:WordPress根目录(Root)
index.php:WordPress核心索引文件,即博客输出文件. license.txt:WordPress GPL许可证文件. my-hacks.php:定义了博客输出之前处理的追加程序.默认安 ...
- 华人曾与IBM抗衡! 盘点已远去的IT巨头(转)
[PConline资讯 ]从算盘到计算器,从大型机到个人PC,再到当今火热的移动终端和云计算,人类计算史已经走过了千年之久,现代IT计算领域也经过了百年浮沉.在世界工业领域,IT技术应该是诞生时间最短 ...
- Navicat(连接) -1之常规设置
常规设置 要成功地创建一个新的连接到本机或远程服务器 - 不管通过 SSL.SSH 或 HTTP,都要在常规选项卡中设置连接属性.如果你的互联网服务供应商(ISP)不提供直接访问其服务器,安全通道协定 ...
- Form_Form树形结构HTree的开发(案例)
2014-06-09 Created By BaoXinjian
- [Offer收割]编程练习赛4 A 满减优惠
满减优惠 描述 最近天气炎热,小Ho天天宅在家里叫外卖.他常吃的一家餐馆一共有N道菜品,价格分别是A1, A2, ... AN元.并且如果消费总计满X元,还能享受优惠.小Ho是一个不薅羊毛不舒服斯基的 ...
- Hadoop Bloom filter应用示例
Hadoop0.20.2 Bloom filter应用示例 2014-06-04 11:55 451人阅读 评论(0) 收藏 举报 1. 简介 参见<Hadoop in Action>P1 ...
- mysql索引之四(索引使用注意规则:索引失效--存在索引但不使用索引)
但是如果是同样的sql如果在之前能够使用到索引,那么现在使用不到索引,以下几种主要情况: 1. 随着表的增长,where条件出来的数据太多,大于15%,使得索引失效(会导致CBO计算走索引花费大于走全 ...
- android之AutoCompleteTextView控件用法
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...