## 題解 ### 哈希表遞歸 ```python= """ # Definition for a Node. class Node: def __init__(self, x: int, next: 'Node' = None, random: 'Node' = None): self.val = int(x) self.next = next self.random = random """ class Solution: def __init__(self): self.map = {} def copyRandomList(self, head: 'Optional[Node]') -> 'Optional[Node]': if not head: return None if head not in self.map: head_next = Node(head.val) self.map[head] = head_next head_next.next = self.copyRandomList(head.next) head_next.random = self.copyRandomList(head.random) return self.map[head] ```