138. Copy List with Random Pointer

知道就是知道,不知道就是不知道

circle-check

Key idea: insert copy of each node into original list

0, Original list
1, Copy "next" and "value" into the original list
2, Copy "random"
3, Split original list and copy list, return copy head

Solution:

  1. copy next

  2. copy random

  3. split origin and copy

triangle-exclamation

别忘了最后将orignial list指针next还原

triangle-exclamation

Last updated