0%

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

题目

原题在此

解析

点踩比点赞多的一道题,配不上中等难度.你可以用任意方式遍历二叉树直到找到target为止.

代码

1
2
3
4
5
6
7
8
9
class Solution {
public:
TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNode* target) {
if(original == target || original == NULL) return cloned;
TreeNode *t = getTargetCopy(original -> left, cloned -> left, target);
if(t == NULL) t = getTargetCopy(original -> right, cloned -> right, target);
return t;
}
};