Simple C++ solution ez


#1
TreeNode* merge(TreeNode *A, TreeNode *B){
    if(A == nullptr) return B;
    if(B == nullptr) return A;
    
    //if both trees are not null trees
    A->val += B->val;
    A->left = merge(A->left, B->left);
    A->right = merge(A->right, B->right);
    return A;
} 
 
TreeNode* Solution::solve(TreeNode* A, TreeNode* B) {
    TreeNode *res = merge(A,B);
    return res;
}

#2

What is wrong with this solution?

TreeNode* Solution::solve(TreeNode* A, TreeNode* B) {
    
    if(B==NULL) return A;
    if(A== NULL) return B;
    
    TreeNode* root;
    root->val = (A->val)+(B->val);
    root->left = solve(A->left, B->left);
    root->right = solve(A->right, B->right);
    return root;
    
}