Complete-Preparation

🎉 One-stop destination for all your technical interview Preparation 🎉

View the Project on GitHub

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

DFS

Code

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);
        TreeNode* right = getTargetCopy(original->right, cloned->right, target);
        return left != NULL ? left : right;
    }
};