1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */
class Solution { public final TreeNode getTargetCopy(final TreeNode original, final TreeNode cloned, final TreeNode target) { if (original == null) { return null; } else if (original == target) { return cloned; } TreeNode ans = this.getTargetCopy(original.left, cloned.left, target); if (ans != null) { return ans; } return this.getTargetCopy(original.right, cloned.right, target); } }
|