From 17d56ed722d41a8d463de2de71c72345a88a2df5 Mon Sep 17 00:00:00 2001 From: jinbudaily <18336218010@163.com> Date: Tue, 18 Jul 2023 15:30:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=200142.=E7=8E=AF=E5=BD=A2?= =?UTF-8?q?=E9=93=BE=E8=A1=A8II=20=E6=8E=92=E7=89=88=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0141.环形链表.md | 11 ++++++----- problems/0142.环形链表II.md | 30 +++++++++++++++--------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/problems/0141.环形链表.md b/problems/0141.环形链表.md index 7d7121a0..b1f42ba9 100644 --- a/problems/0141.环形链表.md +++ b/problems/0141.环形链表.md @@ -70,7 +70,7 @@ public: ## 其他语言版本 -### Java +### Java: ```java public class Solution { @@ -90,7 +90,7 @@ public class Solution { } ``` -### Python +### Python: ```python class Solution: @@ -105,7 +105,7 @@ class Solution: return False ``` -### Go +### Go: ```go func hasCycle(head *ListNode) bool { @@ -125,7 +125,7 @@ func hasCycle(head *ListNode) bool { } ``` -### JavaScript +### JavaScript: ```js var hasCycle = function(head) { @@ -141,7 +141,7 @@ var hasCycle = function(head) { }; ``` -### TypeScript +### TypeScript: ```typescript function hasCycle(head: ListNode | null): boolean { @@ -163,3 +163,4 @@ function hasCycle(head: ListNode | null): boolean { + diff --git a/problems/0142.环形链表II.md b/problems/0142.环形链表II.md index f87d2cd9..d20101a7 100644 --- a/problems/0142.环形链表II.md +++ b/problems/0142.环形链表II.md @@ -11,7 +11,7 @@ > 找到有没有环已经很不容易了,还要让我找到环的入口? -## 142.环形链表II +# 142.环形链表II [力扣题目链接](https://leetcode.cn/problems/linked-list-cycle-ii/) @@ -24,9 +24,11 @@ ![循环链表](https://code-thinking-1253855093.file.myqcloud.com/pics/20200816110112704.png) -## 思路 +## 算法公开课 -《代码随想录》算法公开课:[把环形链表讲清楚!| LeetCode:142.环形链表II](https://www.bilibili.com/video/BV1if4y1d7ob),相信结合视频在看本篇题解,更有助于大家对链表的理解。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[把环形链表讲清楚!| LeetCode:142.环形链表II](https://www.bilibili.com/video/BV1if4y1d7ob),相信结合视频在看本篇题解,更有助于大家对链表的理解。** + +## 思路 这道题目,不仅考察对链表的操作,而且还需要一些数学运算。 @@ -148,7 +150,7 @@ public: * 时间复杂度: O(n),快慢指针相遇前,指针走的次数小于链表长度,快慢指针相遇后,两个index指针走的次数也小于链表长度,总体为走的次数小于 2n * 空间复杂度: O(1) -## 补充 +### 补充 在推理过程中,大家可能有一个疑问就是:**为什么第一次在环中相遇,slow的 步数 是 x+y 而不是 x + 若干环的长度 + y 呢?** @@ -190,8 +192,7 @@ public: ## 其他语言版本 - -Java: +### Java: ```java public class Solution { @@ -217,8 +218,7 @@ public class Solution { } ``` - -Python: +### Python: ```python (版本一)快慢指针法 @@ -270,7 +270,7 @@ class Solution: return None ``` -Go: +### Go: ```go func detectCycle(head *ListNode) *ListNode { @@ -290,7 +290,7 @@ func detectCycle(head *ListNode) *ListNode { } ``` -javaScript +### JavaScript ```js // 两种循环实现方式 @@ -334,7 +334,7 @@ var detectCycle = function(head) { }; ``` -TypeScript: +### TypeScript: ```typescript function detectCycle(head: ListNode | null): ListNode | null { @@ -356,7 +356,7 @@ function detectCycle(head: ListNode | null): ListNode | null { }; ``` -Swift: +### Swift: ```swift class Solution { @@ -391,7 +391,7 @@ extension ListNode: Equatable { } ``` -C: +### C: ```c ListNode *detectCycle(ListNode *head) { @@ -410,7 +410,7 @@ ListNode *detectCycle(ListNode *head) { } ``` -Scala: +### Scala: ```scala object Solution { @@ -437,7 +437,7 @@ object Solution { } ``` -C#: +### C#: ```CSharp public class Solution {