Simple c++ solution in 0(n)


#1

TreeNode* merge(TreeNode* A,TreeNode* B)
{

 if(A==NULL &&  B==NULL)
 return NULL;
 if(A==NULL && B!=NULL)
 return B;
 if(A!=NULL && B==NULL)
 return A;
     
 else  {
     
     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) {

return merge(A,B);

}