/**
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
class Solution {
public:
/**
*
* @param t1 TreeNode类
* @param t2 TreeNode类
* @return TreeNode类
*/
void function(TreeNode* t1, TreeNode* t2) {
if(!t1 && !t2)
return;
t1->val += t2->val;
if(t1->left && t2->left)
function(t1->left, t2->left);
if(!t1->left && t2->left) {
t1->left = new TreeNode(0);
function(t1->left, t2->left);
}
if(t1->left && !t2->left) {
t2->left = new TreeNode(0);
function(t1->left, t2->left);
}
if(t1->right && t2->right)
function(t1->right, t2->right);
if(!t1->right && t2->right) {
t1->right = new TreeNode(0);
function(t1->right, t2->right);
}
if(t1->right && !t2->right) {
t2->right = new TreeNode(0);
function(t1->right, t2->right);
}
return;
}
TreeNode* mergeTrees(TreeNode* t1, TreeNode* t2) {
// write code here
function(t1, t2);
return t1;
}
};