Binary Tree Postorder Traversal
LeetCode 145 • Easy • Trees
Input: root = [1,2,3,4,5] → Output: [4,5,2,3,1]
Iterative trick: root-right-left stack walk, then ans[::-1] (left-right-root).
TimeO(n)visit each node
SpaceO(n)stack + ans
Stack: []Ans: []
Current
In Stack
In Ans
Stack
empty
Ans
[]
Ready
Press Play. One stack: pop, append, push left then right. Reverse at end.