python solution

```
class Solution(object):
def mergeTrees(self, t1, t2):
if t1 and t2:
root = TreeNode(t1.val + t2.val)
root.left = self.mergeTrees(t1.left, t2.left)
root.right = self.mergeTrees(t1.right, t2.right)
return root
else:
return t1 or t2
```

c++ solution

```
class Solution {
public:
TreeNode* mergeTrees(TreeNode* t1, TreeNode* t2) {
if ( t1 && t2 ) {
TreeNode * root = new TreeNode(t1->val + t2->val);
root->left = mergeTrees(t1->left, t2->left);
root->right = mergeTrees(t1->right, t2->right);
return root;
} else {
return t1 ? t1 : t2;
}
}
};
```