1. 题意
对于一个克隆的二叉树,找到与原二叉树相同的节点。
找出克隆二叉树中的相同节点
2. 题解
直接dfs搜索即可
/*** Definition for a binary tree node.* struct TreeNode {* int val;* TreeNode *left;* TreeNode *right;* TreeNode(int x) : val(x), left(NULL), right(NULL) {}* };*/class Solution {
public:TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNode* target) {if (original == NULL)return NULL;if (original == target) {return cloned;}TreeNode *left = getTargetCopy(original->left, cloned->left, target);if (left)return left;return getTargetCopy(original->right, cloned->right, target);}
};