LeetCode: Trees (3)
LeetCode: Trees (3) Originally published in Chinese on 2019-08-24; this English edition preserves the original scope and technical context. Title 4. Recursive solution 617 Merge Binary Trees Merge two binary trees. Determine whether each node exists and merge them all into one tree. class Solution { public: TreeNode *mergeTrees(TreeNode *t1, TreeNode *t2) { if (!t1 && !t2) return nullptr; else if (!t1) return t2; else if (!t2) return t1; t1->val += t2->val; t1->left = mergeTrees(t1->left, t2->left); t1->right = mergeTrees(t1->right, t2->right); return t1; } }; 226 Invert Binary Tree Flip a binary tree. ...