class Solution:
# clone的题目也是在: 构建一棵树.
# 更好的方式确实也需要保存一个map, 由于random的存在. https://algo.monster/liteproblems/1485
def clone_random_tree(self, root: RandomTreeNode) -> RandomTreeNode:
if not root:
return None
copy = RandomTreeNode(root.val, None)
copy.left = self.clone_random_tree(root.left)
copy.right = self.clone_random_tree(root.right)
if root.random:
copy.random = self.clone_random_tree(root.random)
return copy