filmov
tv
617. Merge Two Binary Trees - Javascript Tutorial - Leetcode

Показать описание
This problem can be tricky. You need to use recursion. You also need to keep in mind the condition when there isn't a node in either tree, or one tree has the node but the other doesn't. In that case, add the node from the tree that has it.
If they bot have a node at that position, add the values of the second tree to the first.
Then return the first tree with the changed values.
If they bot have a node at that position, add the values of the second tree to the first.
Then return the first tree with the changed values.