C++ recursive approach


#1

TreeNode* Solution::solve(TreeNode* t1, TreeNode* t2) {
TreeNode* temp = new TreeNode(0);
if(!t1 && !t2)
return NULL;
if(!t1)
return t2;
if(!t2)
return t1;
if(t1 && t2){
temp->val = t1->val + t2->val;
temp->left = solve(t1->left,t2->left);
temp->right = solve(t1->right,t2->right);
}
return temp;
}