Skip to content

Commit 444a438

Browse files
committed
Solution as on 19-02-2022 07:31 am
1 parent 1e97416 commit 444a438

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

0617. Merge Two Binary Trees.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// 617.✅ Merge Two Binary Trees
2+
3+
class Solution
4+
{
5+
public:
6+
TreeNode *mergeTrees(TreeNode *root1, TreeNode *root2)
7+
{
8+
if (root1 != NULL && root2 != NULL)
9+
{
10+
root1->val += root2->val;
11+
root1->left = mergeTrees(root1->left, root2->left);
12+
root1->right = mergeTrees(root1->right, root2->right);
13+
}
14+
else
15+
{
16+
if (root1 != NULL)
17+
return root1;
18+
else
19+
return root2;
20+
}
21+
22+
return root1;
23+
}
24+
};

0 commit comments

Comments
 (0)