EZPZ C++ recursive solution


#1
void build(TreeNode* a, TreeNode* b)
{
    if(!a&&!b)
    {
        return;
    }
    a->val=a->val+b->val;
    if(!a->left&&b->left)
    {
        a->left=new TreeNode(0);
    }
    else if(a->left&&!b->left)
    {
        b->left=new TreeNode(0);
    }
    if(!a->right&&b->right)
    {
        a->right=new TreeNode(0);
    }
    else if(a->right&&!b->right)
    {
        b->right=new TreeNode(0);
    }
    build(a->left,b->left);
    build(a->right,b->right);
}


TreeNode* Solution::solve(TreeNode* A, TreeNode* B) {
    build(A,B);
    return A;
}