Easy
Quiz
#617 Merge Two Binary Trees
APPROACH
You are given two binary trees root1 and root2. Overlay them starting from their roots: wherever both trees have a node, the merged node's value is the sum of the two values; where only one tree has a node, that node carries into the result unchanged. Return the resulting merged tree.
Example 1:
Input: root1 = [1,3,2,5], root2 = [2,1,3,null,4,null,7]
Output: [3,4,5,5,4,null,7]
Example 2:
Input: root1 = [1], root2 = [1,2]
Output: [2,2]
1 of 4
1:00
What is the optimal approach for this problem?