Simple CPP recursive solution


#1

void help(TreeNode* t1, TreeNode* t2,TreeNode parent,bool dirr){
if(t1==NULL && t2==NULL){
return;
}
if(t2==NULL){
return;
}
if(t1==NULL){
TreeNode
temp;

        temp=t2;
        if(dirr){
            parent->right=temp;
            return;
        }
        else{
           parent->left=temp;
            return; 
        }
    }
    t1->val+=(t2->val);
    help(t1->left,t2->left,t1,false);
    help(t1->right,t2->right,t1,true);
}

TreeNode* Solution::solve(TreeNode* t1, TreeNode* t2) {

if(t1==NULL){
        return t2;
    }
    if(t2==NULL){
        return t1;
    }
    help(t1,t2,t1,NULL);
    return t1;

}