1 class Solution: 2 def __init__(self): 3 self.result = TreeNode(-1) 4 5 def preOrder(self,node,target): 6 if node != None: 7 if node.val == target.val: 8 self.result = node 9 return 10 self.preOrder(node.left,target) 11 self.preOrder(node.right,target) 12 13 def getTargetCopy(self, original: TreeNode, cloned: TreeNode, target: TreeNode) -> TreeNode: 14 self.preOrder(cloned,target) 15 return self.result
算法思路:二叉树遍历。