Leetcode_237_Delete Node in a Linked List
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/47334649
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.
思路:
(1)该题为给定一个链表中的一个节点,要求删除该节点。
(2)该题主要对链表存储的考察。在一般情况下,要删除链表的一个节点,需要知道当前节点的前驱节点。该题没有给出前驱节点,所以就需要将当前节点的后继节点的值复制到当前节点,然后删除后继节点即可。
(3)该题比较简单。详情见下方代码。希望本文对你有所帮助。
算法代码实现如下:
package leetcode; import leetcode.utils.ListNode; /** * * @author lqq * */ public class Delete_Node_in_a_LinkedList { public void deleteNode(ListNode node) { if (node == null) return; ListNode after = node.next; if (after != null) { int value = after.val; node.val = value; node.next = after.next; } } }
Leetcode_237_Delete Node in a Linked List的更多相关文章
- [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 ...
- 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 ...
- 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_237】Delete Node in a Linked List
Delete Node in a Linked List Total Accepted: 48121 Total Submissions: 109297 Difficulty: Easy Write ...
- Leetcode-237 Delete Node in a Linked List
#237. Delete Node in a Linked List Write a function to delete a node (except the tail) in a singl ...
- [CareerCup] 2.3 Delete Node in a Linked List 删除链表的节点
2.3 Implement an algorithm to delete a node in the middle of a singly linked list, given only access ...
- (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: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 & 203 - Delete Node in a Linked List & Remove Linked List Elements
237 - Delete Node in a Linked List Write a function to delete a node (except the tail) in a singly l ...
随机推荐
- python 3 黑色魔法元类初探
最近读django源码,发现必须了解元类才能理解一些很神奇的行为. 发现元类实际上是控制class的创建过程.比如类B继承某个看似平淡无奇的类A之后,你在类B中定义的属性或方法可能会遭到彻底改变. 假 ...
- Python 3.3.3 使用requests模拟登录网站
在模拟登录上,requests确实比python标准库中的相关模块更加简洁. 假设你需要去爬一组页面(targetUrls),而这些页面要登录才能进行访问.那么requests能够提供一种相当简单的语 ...
- 关于在页面中针对不同版本的IE浏览器实现不同的JS或者CSS样式
一般会用到<!--[if IE]>这里是正常的html代码<![endif]--> 条件注释只能在windows Internet Explorer(以下简称IE)下使用,因此 ...
- iOS开发之UIWebView的常见一些用法
虽然现在Xcode8已经开始使用WKWebView这个框架进行网页展示,但是UIWebView也有一些常用的方法需要知道,下面就简单展示一下,仅供大家参考 相关知识:1.设置背景透明:2.加载本地HT ...
- Ejb远程调用-jboss服务器调用服务器-Bean调用Bean
英文参考地址 https://docs.jboss.org/author/display/AS71/Remote+EJB+invocations+via+JNDI+-+EJB+client+API+o ...
- Mybatis源码分析之缓存
一.MyBatis缓存介绍 正如大多数持久层框架一样,MyBatis 同样提供了一级缓存和二级缓存的支持 一级缓存: 基于PerpetualCache 的 HashMap本地缓存,其存储作用域为 Se ...
- ExtJS学习(四)EditorGrid可编辑表格
操作表格有一种需求,要操作表格需要动态的添加内容,删除内容以及双击的时候进入编辑状态.这个时候怎么办呢,看具体的实现吧. 双击点击的时候可以单元格的操作. 代码: <!DOCTYPE html& ...
- Android 9Patch图片的使用-android学习之旅(十八)
9patch的使用方法 9patch图片常被用来做消息发送等的图片,只是缩放照片的部分区域,使得图片的整体形状不会受到影响,比较方便. 下面我们介绍一下: 在android的SDK安装目录下的tool ...
- 【java集合框架源码剖析系列】java源码剖析之java集合中的折半插入排序算法
注:关于排序算法,博主写过[数据结构排序算法系列]数据结构八大排序算法,基本上把所有的排序算法都详细的讲解过,而之所以单独将java集合中的排序算法拿出来讲解,是因为在阿里巴巴内推面试的时候面试官问过 ...
- [IDE工具配置]myeclipse 2014 专业版 安装 svn插件
本文地址:http://blog.csdn.net/sushengmiyan/article/details/38342411 本文作者:sushengmiyan 团队合作的项目肯定少不了版本控制,那 ...