You are given the root nodes of two binary trees, root1 and root2.
Merge the two trees into a single binary tree. When two nodes overlap, their values are summed up to create the new value for the merged node. If a node exists in only one tree at a given position, that non null node is used directly in the merged tree.
Return the root of the merged binary tree.
Note: The merging process begins at the root nodes of both trees.
Constraints:
The number of nodes in both trees is in the range
Node.val
You are given the root nodes of two binary trees, root1 and root2.
Merge the two trees into a single binary tree. When two nodes overlap, their values are summed up to create the new value for the merged node. If a node exists in only one tree at a given position, that non null node is used directly in the merged tree.
Return the root of the merged binary tree.
Note: The merging process begins at the root nodes of both trees.
Constraints:
The number of nodes in both trees is in the range
Node.val