删除链表的一个结点,用下一个结点覆盖掉要删除的结点,再释放掉要删结点的下一个结点的内存

Java:

 public ListNode deleteNode(ListNode head, ListNode tobeDelete) {
if (head == null || head.next == null || tobeDelete == null) return null;
if (tobeDelete.next != null) {
// 要删除的节点不是尾节点
ListNode next = tobeDelete.next;
tobeDelete.val = next.val;
tobeDelete.next = next.next;
} else {
ListNode cur = head;
while (cur.next != tobeDelete) cur = cur.next;
cur.next = null;
}
return head;
}

最新文章

  1. Lesson 7 Too late
  2. UIToolBar
  3. UI第十三节——UIActionSheet
  4. pip和easy_install更换使用国内源
  5. Ubuntu下使用SVN
  6. [Tools] Eclipse使用小技巧-持续更新
  7. java 程序访问hdfs错误 hadoop2.2.0
  8. (zz) 谷歌技术"三宝"之BigTable
  9. JMeter教程01-下载和安装
  10. http://jingyan.baidu.com/article/fcb5aff78e6a48edab4a7146.html
  11. List null
  12. Java 中的抽象类及接口
  13. Android之开源项目view篇
  14. DependencyProperty
  15. 解析word中的表格
  16. CSS的标签类型
  17. bzoj4826 [Hnoi2017]影魔
  18. DIY 温控烙铁
  19. 下一个ajax异步请求被挂起问题
  20. .net core EFCore CodeFirst 迁移出现错误【No project was found. Change the current working directory or use the --project option. 】

热门文章

  1. 第一天:简单工厂模式与UML类图
  2. Rigidbody和Collider
  3. 总结: 《jQuery基础教程》 1-4章
  4. activity 中获取控件的宽高
  5. 手把手教你在.NET中创建Web服务
  6. iOS程序启动过程笔记
  7. 配置SpringBoot-从日志系统配置说起
  8. [HNOI2008]越狱 题解(容斥原理+快速幂)
  9. 【译】第十四篇 Integration Services:项目转换
  10. UNIX环境高级编程 第11章 线程