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相关推荐

  1. [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 ...

  2. LintCode Delete Node in the Middle of Singly Linked List 在O(1)时间复杂度删除链表节点

    中文描述: 给定一个单链表中的表头和一个等待被删除的节点(非表头或表尾).请在在O(1)时间复杂度删除该链表节点.并在删除该节点后,返回表头. 样例 给定 1->2->3->4,和节 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. C#LeetCode刷题之#237-删除链表中的节点(Delete Node in a Linked List)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3832 访问. 请编写一个函数,使其可以删除某个链表中给定的(非末 ...

最新文章

  1. C++——运算符重载operator
  2. 关于Puremvc的理解
  3. P6623-[省选联考2020A卷]树【Trie,树上启发式合并】
  4. java main方法里调用mapper
  5. 第二十期:核心交换机的链路聚合、冗余、堆叠、热备份
  6. arm+linux+entry.s,linux kernel 之底层中断机制entry_armv.S
  7. CentOS6.5安装python2.7.6(慎重升级)
  8. 年度调薪一般涨多少_宁愿辞职也不敢提加薪,心理专家告诉你加薪提多少才合适...
  9. php面向对象封装mysql_PHP mysqli 扩展库(面向对象/数据库操作封装/事务控制/预编译)...
  10. 安利几个优质nlp开源项目
  11. sql语句分组mysql_MySQL GROUP BY 语句_sql语句group by_分组
  12. 如何用cv2.imread()读取falsk接收的图片
  13. Spring Could+Ant Design Pro表格数据加载
  14. CMMI5 2.0版本是什么 做什么
  15. 华硕ARMOURY CRATE奥创安装/风扇快捷键问题
  16. CAD贱人工具箱插件免费下载
  17. 影响中国信息化全面预算管理的十大案例
  18. 【web-攻击验证机制】(3.2.3)验证机制设计缺陷:“记住密码” 功能、用户伪装功能、证书确认不完善
  19. python学习-day18、文件处理、
  20. ipa包的简单校验方法

热门文章

  1. 上海雄联机械配件有限公司
  2. Oracle存储过程基本语法
  3. Linux---进程间通信
  4. 镇政府事业编怎么样,工作压力大吗?
  5. 手机充电全部用完充好还是有空就充好?
  6. 买彩票中奖的概率是多少?
  7. 小小芯片上的上千万个晶体管是怎么装上去的
  8. 互联网产品经理的核心竞争力是什么呢?
  9. 有个做微商的兄弟,他是卖品牌运动鞋的,最近很苦恼
  10. 30岁以后的人生,如何来逆袭?