重排链表
This commit is contained in:
37
1.重排链表/题目.md
Normal file
37
1.重排链表/题目.md
Normal file
@ -0,0 +1,37 @@
|
||||
给定一个单链表 L 的头节点 head ,单链表 L 表示为:
|
||||
|
||||
```
|
||||
L0 → L1 → … → Ln - 1 → Ln
|
||||
```
|
||||
请将其重新排列后变为:
|
||||
|
||||
```
|
||||
L0 → Ln → L1 → Ln - 1 → L2 → Ln - 2 → …
|
||||
```
|
||||
不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换。
|
||||
|
||||
|
||||
|
||||
示例 1:
|
||||
|
||||
![1626420311-PkUiGI-image[1].png](https://picbed.hiiragi.club:8081/i/2023/07/31/64c74c89a9ff8.png)
|
||||
|
||||
```
|
||||
输入:head = [1,2,3,4]
|
||||
输出:[1,4,2,3]
|
||||
```
|
||||
示例 2:
|
||||
|
||||
![1626420320-YUiulT-image[1].png](https://picbed.hiiragi.club:8081/i/2023/07/31/64c74c8a1d9a8.png)
|
||||
|
||||
```
|
||||
输入:head = [1,2,3,4,5]
|
||||
输出:[1,5,2,4,3]
|
||||
```
|
||||
|
||||
|
||||
提示:
|
||||
|
||||
- 链表的长度范围为 `[1, 5 * 104]`
|
||||
|
||||
- `1 <= node.val <= 1000`
|
Reference in New Issue
Block a user