Find a Corresponding Node of a Binary Tree in a Clone of That Tree

给一个树和一个target node, 找早cloned里边的这个node.

这个题已知这个node一定存在, 并且唯一.

/**
 * 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;
        if(original.val == target.val){
            return cloned;
        }
        TreeNode left = getTargetCopy(original.left, cloned.left, target);
        TreeNode right = getTargetCopy(original.right, cloned.right, target);
        if(left != null)
            return left;
        else
            return right;
    }
}