From 4b4bc029a237f07bd61b4b125b15d64cca158963 Mon Sep 17 00:00:00 2001 From: Omooo <869759698@qq.com> Date: Wed, 3 Jun 2020 10:06:41 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E9=93=BE=E8=A1=A8=E7=9B=B8=E5=85=B3.m?= =?UTF-8?q?d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blogs/Algorithm/剑指 Offer/链表相关.md | 30 +++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/blogs/Algorithm/剑指 Offer/链表相关.md b/blogs/Algorithm/剑指 Offer/链表相关.md index 3e38def..28c1be0 100644 --- a/blogs/Algorithm/剑指 Offer/链表相关.md +++ b/blogs/Algorithm/剑指 Offer/链表相关.md @@ -2,6 +2,15 @@ 链表相关 --- +#### 目录 + +1. [06. 从头到尾打印链表](https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/) +2. [18. 删除链表的节点](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) +3. [22. 链表中倒数第 k 个节点](https://leetcode-cn.com/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/) +4. [24. 反转链表](https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof/) +5. [25. 合并两个排序的链表](https://leetcode-cn.com/problems/he-bing-liang-ge-pai-xu-de-lian-biao-lcof/) +6. [35. 复杂链表的复制](https://leetcode-cn.com/problems/fu-za-lian-biao-de-fu-zhi-lcof/) + [06. 从头到尾打印链表](https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/) ```java @@ -43,6 +52,26 @@ class Solution { } ``` +[18. 删除链表的节点](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) + +```java +class Solution { + public ListNode deleteNode(ListNode head, int val) { + ListNode h0 = new ListNode(0); + ListNode h1 = h0; + h0.next = head; + while (h0.next != null) { + if (h0.next.val == val) { + h0.next = h0.next.next; + break; + } + h0 = h0.next; + } + return h1.next; + } +} +``` + [22. 链表中倒数第 k 个节点](https://leetcode-cn.com/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/) ```java @@ -263,4 +292,3 @@ public class Solution { } } ``` -