Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1528 from julienChemillier/patch-48
Browse files Browse the repository at this point in the history
Add 617 in c language
  • Loading branch information
Ahmad-A0 authored Dec 22, 2022
2 parents c2af140 + 76bff17 commit 53f2e7b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions c/617-Merge-Two-Binary-Trees.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
You are given two binary trees root1 and root2.
Return the merged tree
Time: O(n)
Space: O(1) As we reuse the trees
*/

struct TreeNode* mergeTrees(struct TreeNode* root1, struct TreeNode* root2){
if (root1==NULL)
return root2;
else if (root2==NULL)
return root1;
root1->val += root2->val;
root1->left = mergeTrees(root1->left, root2->left);
root1->right = mergeTrees(root1->right, root2->right);
return root1;
}

0 comments on commit 53f2e7b

Please sign in to comment.