Skip to content

Commit b867080

Browse files
committed
206-reverse-linked-list.md Separated Chinese solutions from English solutions.
1 parent 0ea30cc commit b867080

File tree

3 files changed

+34
-165
lines changed

3 files changed

+34
-165
lines changed

en/1-1000/206-reverse-linked-list.md

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
# 206. Reverse Linked List - Best Practices of LeetCode Solutions
2-
LeetCode link: [206. Reverse Linked List](https://leetcode.com/problems/reverse-linked-list),
3-
[206. 反转链表](https://leetcode.cn/problems/reverse-linked-list)
2+
LeetCode link: [206. Reverse Linked List](https://leetcode.com/problems/reverse-linked-list), difficulty: **Easy**.
43

5-
[中文题解](#中文题解)
6-
7-
## LeetCode problem description
4+
## LeetCode description of "206. Reverse Linked List"
85
Given the `head` of a singly linked list, reverse the list, and return _the reversed list_.
96

107
### [Example 1]
@@ -31,13 +28,11 @@ Given the `head` of a singly linked list, reverse the list, and return _the reve
3128
- `-5000 <= Node.val <= 5000`
3229

3330
## Intuition
34-
[中文题解](#中文题解)
35-
3631
1. To solve this problem, we only need to define **two** variables: `current` and `previous`.
3732
2. `current.next = previous` is the inversion.
3833
3. The loop condition should be `while (current != null)` instead of `while (current.next != null)`, because the operation to be performed is `current.next = previous`.
3934

40-
## Steps to the Solution
35+
## Steps
4136
1. Traverse all nodes.
4237
```javascript
4338
previous = null
@@ -284,55 +279,3 @@ end
284279
```
285280
// Welcome to create a PR to complete the code of this language, thanks!
286281
```
287-
288-
## 问题描述
289-
290-
291-
### [Example 1]
292-
给你单链表的头节点 `head` ,请你反转链表,并返回反转后的链表。
293-
294-
**输入**: `head = [1,2,3,4,5]`
295-
296-
**输出**: `[5,4,3,2,1]`
297-
298-
## 中文题解
299-
### 思路
300-
1. 解决这个问题,只需要定义****个变量:`current``previous`
301-
2. `current.next = previous`就是反转了。
302-
3. 循环条件应是`while (current != null)`,而不应该是`while (current.next != null)`,因为需要操作的是`current.next = previous`.
303-
304-
### 步骤
305-
1. 遍历所有节点。
306-
```javascript
307-
previous = null
308-
current = head
309-
310-
while (current != null) {
311-
current = current.next
312-
}
313-
```
314-
315-
2. 加入`current.next = previous`
316-
```javascript
317-
previous = null
318-
current = head
319-
320-
while (current != null) {
321-
tempNext = current.next
322-
current.next = previous
323-
current = tempNext
324-
}
325-
```
326-
327-
3. `previous`目前始终是`null`,需要让它变化起来:`previous = current`
328-
```javascript
329-
previous = null
330-
current = head
331-
332-
while (current != null) {
333-
tempNext = current.next
334-
current.next = previous
335-
previous = current
336-
current = tempNext
337-
}
338-
```

en/3001-4000/unorganized.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,4 @@ Add a table to show the differences between A-Start and breadth-first search
205205
- https://leetcode.com/problems/k-closest-points-to-origin/
206206
- https://leetcode.com/problems/find-special-substring-of-length-k/
207207
- https://leetcode.cn/problems/eat-pizzas/
208-
-
208+
- https://leetcode.cn/problems/merge-intervals/

zh/1-1000/206-reverse-linked-list.md

Lines changed: 30 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,39 @@
1-
# 206. Reverse Linked List - Best Practices of LeetCode Solutions
2-
LeetCode link: [206. Reverse Linked List](https://leetcode.com/problems/reverse-linked-list),
3-
[206. 反转链表](https://leetcode.cn/problems/reverse-linked-list)
1+
# 206. 反转链表 - 力扣题解最佳实践
2+
力扣链接:[206. 反转链表](https://leetcode.cn/problems/reverse-linked-list) ,难度:**简单**
43

5-
[中文题解](#中文题解)
6-
7-
## LeetCode problem description
8-
Given the `head` of a singly linked list, reverse the list, and return _the reversed list_.
4+
## 力扣“206. 反转链表”问题描述
5+
给你单链表的头节点 `head` ,请你反转链表,并返回反转后的链表。
96

10-
### [Example 1]
7+
### [示例 1]
118
![](../../images/examples/206_1.jpg)
129

13-
**Input**: `head = [1,2,3,4,5]`
10+
**输入**: `head = [1,2,3,4,5]`
1411

15-
**Output**: `[5,4,3,2,1]`
12+
**输出**: `[5,4,3,2,1]`
1613

17-
### [Example 2]
14+
### [示例 2]
1815
![](../../images/examples/206_2.jpg)
1916

20-
**Input**: `[1,2]`
17+
**输入**: `[1,2]`
2118

22-
**Output**: `[2,1]`
19+
**输出**: `[2,1]`
2320

24-
### [Example 3]
25-
**Input**: `[]`
21+
### [示例 3]
22+
**输入**: `[]`
2623

27-
**Output**: `[]`
24+
**输出**: `[]`
2825

29-
### [Constraints]
30-
- The number of nodes in the list is the range `[0, 5000]`.
26+
### [约束]
27+
- 链表中节点的数目范围是 `[0, 5000]`
3128
- `-5000 <= Node.val <= 5000`
3229

33-
## Intuition
34-
[中文题解](#中文题解)
35-
36-
1. To solve this problem, we only need to define **two** variables: `current` and `previous`.
37-
2. `current.next = previous` is the inversion.
38-
3. The loop condition should be `while (current != null)` instead of `while (current.next != null)`, because the operation to be performed is `current.next = previous`.
30+
## 思路
31+
1. 解决这个问题,只需要定义****个变量:`current``previous`
32+
2. `current.next = previous`就是反转了。
33+
3. 循环条件应是`while (current != null)`,而不应该是`while (current.next != null)`,因为需要操作的是`current.next = previous`.
3934

40-
## Steps to the Solution
41-
1. Traverse all nodes.
35+
## 步骤
36+
1. 遍历所有节点。
4237
```javascript
4338
previous = null
4439
current = head
@@ -48,7 +43,7 @@ while (current != null) {
4843
}
4944
```
5045

51-
2. Add `current.next = previous`.
46+
2. 加入`current.next = previous`
5247
```javascript
5348
previous = null
5449
current = head
@@ -60,7 +55,7 @@ while (current != null) {
6055
}
6156
```
6257

63-
3. `previous` is always `null`, we need to change it: `previous = current`.
58+
3. `previous`目前始终是`null`,需要让它变化起来:`previous = current`
6459
```javascript
6560
previous = null
6661
current = head
@@ -73,9 +68,12 @@ while (current != null) {
7368
}
7469
```
7570

76-
## Complexity
77-
* Time: `O(n)`.
78-
* Space: `O(1)`.
71+
## 复杂度
72+
* 时间:`O(N)`
73+
* 空间:`O(1)`
74+
75+
## 进阶
76+
链表可以选用迭代或递归方式完成反转。你能否用两种方法解决这道题?
7977

8078
## Java
8179
```java
@@ -260,79 +258,7 @@ def reverse_list(head)
260258
end
261259
```
262260

263-
## C
264-
```c
265-
// Welcome to create a PR to complete the code of this language, thanks!
266-
```
267-
268-
## Kotlin
269-
```kotlin
270-
// Welcome to create a PR to complete the code of this language, thanks!
271-
```
272-
273-
## Swift
274-
```swift
275-
// Welcome to create a PR to complete the code of this language, thanks!
261+
## C, Kotlin, Swift, Rust or other languages
276262
```
277-
278-
## Rust
279-
```rust
280263
// Welcome to create a PR to complete the code of this language, thanks!
281264
```
282-
283-
## Other languages
284-
```
285-
// Welcome to create a PR to complete the code of this language, thanks!
286-
```
287-
288-
## 问题描述
289-
290-
291-
### [Example 1]
292-
给你单链表的头节点 `head` ,请你反转链表,并返回反转后的链表。
293-
294-
**输入**: `head = [1,2,3,4,5]`
295-
296-
**输出**: `[5,4,3,2,1]`
297-
298-
## 中文题解
299-
### 思路
300-
1. 解决这个问题,只需要定义****个变量:`current``previous`
301-
2. `current.next = previous`就是反转了。
302-
3. 循环条件应是`while (current != null)`,而不应该是`while (current.next != null)`,因为需要操作的是`current.next = previous`.
303-
304-
### 步骤
305-
1. 遍历所有节点。
306-
```javascript
307-
previous = null
308-
current = head
309-
310-
while (current != null) {
311-
current = current.next
312-
}
313-
```
314-
315-
2. 加入`current.next = previous`
316-
```javascript
317-
previous = null
318-
current = head
319-
320-
while (current != null) {
321-
tempNext = current.next
322-
current.next = previous
323-
current = tempNext
324-
}
325-
```
326-
327-
3. `previous`目前始终是`null`,需要让它变化起来:`previous = current`
328-
```javascript
329-
previous = null
330-
current = head
331-
332-
while (current != null) {
333-
tempNext = current.next
334-
current.next = previous
335-
previous = current
336-
current = tempNext
337-
}
338-
```

0 commit comments

Comments
 (0)