Post-order traversal
Standard · Write code · about 8 min
Given the root of a binary tree, return the values of its nodes in post-order: the left subtree, then the right subtree, then the node.
Example 1
Input:
[[1,null,2,3]]
Output:
[3,2,1]
Visit 3, then 2, then 1 last.
Example 2
Input:
[[4,2,6,1,3]]
Output:
[1,3,2,6,4]
Constraints
- 0 ≤ number of nodes ≤ 1,000
- -1,000 ≤ Node.val ≤ 1,000
- The tree is given in level order; null marks a missing child
Learn the idea first: Pre-order, in-order, post-order, a visual lesson.
More Pre-order, in-order, post-order problems
- Write the three orders Warm-up
- In-order of a search tree Warm-up
- Complete the in-order traversal Warm-up
- Pre-order traversal Standard
- In-order iteratively Standard
- Fix the post-order traversal Standard
- Build a tree from pre-order and in-order Challenge