Update 35. 复杂链表的复制.md

重新绘制配图,配图补全节点之间的 next 指针。
This commit is contained in:
CyC2018
2026-10-28 22:51:20 +08:00
parent bb6ef54f9a
commit 58ac2fda8b
5 changed files with 4 additions and 4 deletions
+4 -4
View File
@@ -20,21 +20,21 @@ class Node {
}
```
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/66a01953-5303-43b1-8646-0c77b825e980.png" width="300"/> </div><br>
<div align="center"> <img src="pics/offer35-random-list.png" width="380px"/> </div><br>
## 解题思路
第一步,在每个节点的后面插入复制的节点。
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/dfd5d3f8-673c-486b-8ecf-d2082107b67b.png" width="600"/> </div><br>
<div align="center"> <img src="pics/offer35-clone-insert.png" width="690px"/> </div><br>
第二步,对复制节点的 random 链接进行赋值。
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/cafbfeb8-7dfe-4c0a-a3c9-750eeb824068.png" width="600"/> </div><br>
<div align="center"> <img src="pics/offer35-clone-random.png" width="690px"/> </div><br>
第三步,拆分。
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/e151b5df-5390-4365-b66e-b130cd253c12.png" width="600"/> </div><br>
<div align="center"> <img src="pics/offer35-clone-split.png" width="420px"/> </div><br>
```java
public Node copyRandomList(Node head) {
Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB