/** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ /** * * @param t1 TreeNode类 * @param t2 TreeNode类 * @return TreeNode类 */ void ADD(struct TreeNode* t1, struct TreeNode* t2){ t1->val+=t2->val; if(t1->left!=NULL&&t2->left!=NULL) ADD(t1->left,t2->left); if(t1->left==NULL&&t2->left!=NULL) t1->left=t2->left; if(t1->right!=NULL&&t2->right!=NULL) ADD(t1->right,t2->right); if(t1->right==NULL&&t2->right!=NULL) t1->right=t2->right; } struct TreeNode* mergeTrees(struct TreeNode* t1, struct TreeNode* t2 ) { // write code here if(t1==NULL)return t2; if(t2==NULL)return t1; if(!(t1==NULL&&t2==NULL)) { ADD(t1,t2); } return t1; }