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 ...
随机推荐
- Android新建工程步骤(AndroidStudio)
1.在 Android Studio 中,创建新项目: 如果您未打开项目,请在 Welcome to Android Studio 窗口中,点击 Start a new Android Studio ...
- 如何向android studio中导入第三方类库
下面分两种情况介绍一下如何导入第三方类库. 1.对于jar的类库,直接复制进libs目录,然后把jar复制进去,然后File->Project Structure,然后选中主module的名称, ...
- iOS编程Cookbook第19章最后一个例子不能正常工作的解决办法
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) 在Cookbook的第19章的11节中所要解决的是在App中显 ...
- Android View框架总结(七)View事件分发机制
请尊重分享成果,转载请注明出处: http://blog.csdn.net/hejjunlin/article/details/52282833 View布局告一段落,从本篇开始View事件相关分析, ...
- 如何通过网络连接进行ADB调试
点击打开链接 大家在使用adb调试Android系统时可能会遇到麻烦,比如usb端口只有一个,如果用作adb调试,就不能通过usb连接其它器件,或者usb端口不能使用时也没法进行adb调试. Andr ...
- Nginx模块之SessionSticky
0 工作原理 Session Sticky 模块在upstream 返回响应后,向客户的浏览器写入 Cookie ,默认名为route ,保存的内容是一个 md5 码. 之后,模块接收到客户浏览器的请 ...
- Cocos2D iOS之旅:如何写一个敲地鼠游戏(九):创建动画
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! hopy ;) 免责申明:本博客提供的所有翻译文章原稿均来自互联网,仅供学习交流 ...
- Nginx+PHP-FPM的域Socket配置方法
1什么是域Socket "Unix domain socket 或者 IPCsocket 是一种终端,可以使同一台操作系统上的两个或多个进程进行数据通信.与管道相比,Unix domain ...
- Dynamics CRM2013 编辑视图时弹出尚未保存所做的更改警示框
CRM2013中当对视图进行自定义编辑时,总会弹出如下图所示的警示框,一般我们都会选择离开此页来保存我们所做的更改,显而易见的是这又是CRM2013的一个bug 在UR2 for Dynamics ...
- 【一天一道LeetCode】#83. Remove Duplicates from Sorted List
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...