-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprob_1379.java
21 lines (20 loc) · 914 Bytes
/
prob_1379.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class prob_1379 {
public static void main(String[] args) {
Solution_1379 solution = new Solution_1379();
Integer[] nodeList = {7,4,3,null,null,6,19};
TreeNode original = new TreeNode(), cloned = new TreeNode();
original = original.parseTree(nodeList);
cloned = cloned.parseTree(nodeList);
TreeNode target = original.right;
System.out.println(solution.getTargetCopy(original, cloned, target));
}
}
class Solution_1379 {
public final TreeNode getTargetCopy(final TreeNode original, final TreeNode cloned, final TreeNode target) {
if(original == null || cloned == null) return null;
if(original.equals(target)) return cloned;
TreeNode left = this.getTargetCopy(original.left, cloned.left, target);
if(left != null) return left;
return this.getTargetCopy(original.right, cloned.right, target);
}
}