lintcode-easy-Delete Node in the Middle of Singly Linked List
Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node.
Example
Given 1->2->3->4
, and node 3
. return 1->2->4
删除的方法就是用后面的值覆盖前面的值,注意避免OBOB
/*** Definition for ListNode.* public class ListNode {* int val;* ListNode next;* ListNode(int val) {* this.val = val;* this.next = null;* }* }*/ public class Solution {/*** @param node: the node in the list should be deleted* @return: nothing*/public void deleteNode(ListNode node) {// write your code hereListNode p = node;while(p.next.next != null){p.val = p.next.val;p = p.next;}p.val = p.next.val;p.next = null;return;} }
转载于:https://www.cnblogs.com/goblinengineer/p/5213808.html
lintcode-easy-Delete Node in the Middle of Singly Linked List相关推荐
- [LintCode] Delete Node in the Middle of Singly Linked List 在单链表的中间删除节点
Implement an algorithm to delete a node in the middle of a singly linked list, given only access to ...
- LintCode Delete Node in the Middle of Singly Linked List 在O(1)时间复杂度删除链表节点
中文描述: 给定一个单链表中的表头和一个等待被删除的节点(非表头或表尾).请在在O(1)时间复杂度删除该链表节点.并在删除该节点后,返回表头. 样例 给定 1->2->3->4,和节 ...
- Lintcode372 Delete Node in the Middle of Singly Linked List solution 题解
[题目描述] Implement an algorithm to delete a node in the middle of a singly linked list, given only acc ...
- LeetCode刷题记录3——237. Delete Node in a Linked List(easy)
LeetCode刷题记录3--237. Delete Node in a Linked List(easy) 目录 LeetCode刷题记录3--237. Delete Node in a Linke ...
- Leet Code OJ 237. Delete Node in a Linked List [Difficulty: Easy]
题目: Write a function to delete a node (except the tail) in a singly linked list, given only access t ...
- 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 t ...
- 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 t ...
- 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 t ...
- C#LeetCode刷题之#237-删除链表中的节点(Delete Node in a Linked List)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3832 访问. 请编写一个函数,使其可以删除某个链表中给定的(非末 ...
最新文章
- C++——运算符重载operator
- 关于Puremvc的理解
- P6623-[省选联考2020A卷]树【Trie,树上启发式合并】
- java main方法里调用mapper
- 第二十期:核心交换机的链路聚合、冗余、堆叠、热备份
- arm+linux+entry.s,linux kernel 之底层中断机制entry_armv.S
- CentOS6.5安装python2.7.6(慎重升级)
- 年度调薪一般涨多少_宁愿辞职也不敢提加薪,心理专家告诉你加薪提多少才合适...
- php面向对象封装mysql_PHP mysqli 扩展库(面向对象/数据库操作封装/事务控制/预编译)...
- 安利几个优质nlp开源项目
- sql语句分组mysql_MySQL GROUP BY 语句_sql语句group by_分组
- 如何用cv2.imread()读取falsk接收的图片
- Spring Could+Ant Design Pro表格数据加载
- CMMI5 2.0版本是什么 做什么
- 华硕ARMOURY CRATE奥创安装/风扇快捷键问题
- CAD贱人工具箱插件免费下载
- 影响中国信息化全面预算管理的十大案例
- 【web-攻击验证机制】(3.2.3)验证机制设计缺陷:“记住密码” 功能、用户伪装功能、证书确认不完善
- python学习-day18、文件处理、
- ipa包的简单校验方法