#1379
Easy Algorithms Find a corresponding node of a binary tree in a clone of that tree
Tree Depth-First Search Breadth-First Search Binary Tree
85.8% acceptance
Jan 13, 2026
1809
2018
Given two binary trees original and cloned and given a reference to a node target in the original tree.
The cloned tree is a copy of the original tree.
Return a reference to the same node in the cloned tree.
Solution
C++
Time O(1)
Space O(1)
class Solution {
public:
TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNode* target) {
if (!original) return nullptr;
if (original == target) return cloned;
TreeNode* left = getTargetCopy(original->left, cloned->left, target);
return left ? left : getTargetCopy(original->right, cloned->right, target);
}
};