# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = NoneclassSolution:defgetTargetCopy(self,original: TreeNode,cloned: TreeNode,target: TreeNode) -> TreeNode:ifnot original ornot cloned:returnNoneif original == target:return cloned left = self.getTargetCopy(original.left, cloned.left, target)if left:return left right = self.getTargetCopy(original.right, cloned.right, target)return right
# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = NoneclassSolution:defgetTargetCopy(self,original: TreeNode,cloned: TreeNode,target: TreeNode) -> TreeNode: queue =deque([(original, cloned)])while queue: ori, clo = queue.popleft()if ori == target:return cloif ori.left: queue.append((ori.left, clo.left))if ori.right: queue.append((ori.right, clo.right))