Skip to content

Commit 32eabdf

Browse files
author
Joseph Luce
authored
Update 145_binary_tree_postorder_traversal.md
1 parent 1f59565 commit 32eabdf

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

leetcode/hard/145_binary_tree_postorder_traversal.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ class Solution:
2727

2828
## Iterative Solution
2929
- Runtime: O(N)
30-
- Space: O(H)
30+
- Space: O(N)
3131
- N = Number of elements in tree
32-
- H = Height of tree
3332

3433
Take a look back at how a preorder is done (Node -> Left -> Right).
3534
Compared to postorder (Left -> Right -> Node), what are some similarities?
@@ -39,6 +38,9 @@ Another way to look at it is, since postorder is (Left -> Right -> Node), we can
3938

4039
So we can achieve an iterative postorder traversal via. an inverted preorder traversal.
4140

41+
Since we need to use an additional stack/list, which we then reverse as the result, we cannot get O(H) additional space.
42+
The best we can achieve is O(N) space.
43+
4244
```
4345
class Solution:
4446
def postorderTraversal(self, root: TreeNode) -> List[int]:

0 commit comments

Comments
 (0)