更新 0142.环形链表II 排版格式修复

This commit is contained in:
jinbudaily
2023-07-18 15:30:49 +08:00
parent 8eb214c060
commit 17d56ed722
2 changed files with 21 additions and 20 deletions

View File

@ -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 {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

View File

@ -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
{