Skip to content

Commit e3f7bd5

Browse files
author
Joseph Luce
authored
Update 617_merge_two_binary_trees.md
1 parent 9953c15 commit e3f7bd5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

leetcode/easy/617_merge_two_binary_trees.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
## Recursive Solution
44

55
- Runtime: O(N)
6-
- Space: O(N)
6+
- Space: O(H)
77
- N = Number of elements in both trees
8+
- H = Height of highest tree
89

910
By traversing both trees together, the solution is much simpler.
1011
Use one of the trees as your primary merge tree during the recursion and create new nodes when the primary doesn't have one and the secondary tree does.
@@ -36,8 +37,9 @@ class Solution:
3637
## Iterative Solution
3738

3839
- Runtime: O(N)
39-
- Space: O(N)
40+
- Space: O(H)
4041
- N = Number of elements in both trees
42+
- H = Height of highest tree
4143

4244
Similar to the recursion solution, however, we will need to keep two items in each element of the stack.
4345
Since the idea was to traverse the nodes in pairs.

0 commit comments

Comments
 (0)