重排链表

This commit is contained in:
mol
2023-07-31 13:57:28 +08:00
commit ddf756f53d
5 changed files with 220 additions and 0 deletions

37
1.重排链表/题目.md Normal file
View 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`