Find a Corresponding Node of a Binary Tree in a Clone of That Tree LeetCode solution in Java

1
class Solution {
2
public final TreeNode getTargetCopy(
3
final TreeNode original, final TreeNode cloned, final TreeNode target) {
4
TreeNode[] ref = new TreeNode[] {null};
5
dfs(cloned, target, ref);
6
return ref[0];
7
}
8

9
public static void dfs(TreeNode root, TreeNode target, TreeNode[] ref) {
10
if (root == null) return;
11
if (root.val == target.val) {
12
ref[0] = root;
13
return;
14
} else {
15
dfs(root.left, target, ref);
16
dfs(root.right, target, ref);
17
}
18
}
19
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0