Files
2023-07-31 13:57:28 +08:00

37 lines
725 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

给定一个单链表 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`