class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None class Solution: def getTargetCopy(self, original: TreeNode, cloned: TreeNode, target: TreeNode) -> TreeNode: return self.findTarget(cloned, target) def findTarget(self, tree, t): if tree is not None: if tree.val == t.val: return tree leftFound = self.findTarget(tree.left, t) rightFound = self.findTarget(tree.right, t) if leftFound is not None: return leftFound elif rightFound is not None: return rightFound s = Solution() o = TreeNode(1) o.left = TreeNode(3) c = TreeNode(1) t = TreeNode(3) c.left = t print("Expected: 3") print("Got:", s.getTargetCopy(o, c, t).val)