# 617. Merge Two Binary Trees

{% embed url="<https://leetcode.com/problems/merge-two-binary-trees/>" %}

还是递归遍历，只不过同时遍历两个tree，结束条件是其中一个树遍历到叶子了，这时候接下来的subtree就可以直接拿另外一个树的来用。

```python
class Solution:
    def mergeTrees(self, t1: TreeNode, t2: TreeNode) -> TreeNode:
        if not t1: return t2
        if not t2: return t1
        t1.val += t2.val
        t1.left = self.mergeTrees(t1.left, t2.left)
        t1.right = self.mergeTrees(t1.right, t2.right)
        return t1
```
