【数据结构--二叉树】合并二叉树

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */


struct TreeNode* mergeTrees(struct TreeNode* root1, struct TreeNode* root2){
    if(root1==NULL&&root2==NULL)//两个二叉树都是空
        return NULL;
    
    if(root2!=NULL&&root1==NULL)
        return root2;
    if(root1!=NULL&&root2==NULL)
        return root1;

    root1->val=root1->val+root2->val;
    root1->left=mergeTrees(root1->left,root2->left);
    root1->right=mergeTrees(root1->right,root2->right);

    return root1;
}