/**
* 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&&!root2) return NULL;
if(!root1&& root2) return root2;
if(!root2&& root1) return root1;
root1->val=root1->val+root2->val;
root1->left=mergeTrees(root1->left,root2->left);
root1->right=mergeTrees(root1->right,root2->right);
return root1;
}
结果:
标签:right,TreeNode,struct,val,合并,617,二叉树,root1,root2 From: https://www.cnblogs.com/llllmz/p/18072884