617. Merge Two Binary Trees 合并两个二叉树
617. Merge Two Binary Trees
递归!递归!
1 class Solution { 2 public: 3 TreeNode* mergeTrees(TreeNode* t1, TreeNode* t2) { 4 if ( t1 && t2 ) { 5 TreeNode * root = new TreeNode(t1->val + t2->val); 6 root->left = mergeTrees(t1->left, t2->left); 7 root->right = mergeTrees(t1->right, t2->right); 8 return root; 9 } else { 10 return t1 ? t1 : t2; 11 } 12 } 13 };