Binary Tree Postorder Traversal - Problem
Given the root of a binary tree, return the postorder traversal of its nodes' values.
In postorder traversal, we visit nodes in the order: left subtree → right subtree → current node. This means we process all children before processing the parent node.
Note: You may implement this using either recursive or iterative approaches.
Input & Output
Example 1 — Basic Tree
$
Input:
root = [1,null,2,3]
›
Output:
[3,2,1]
💡 Note:
Postorder visits left→right→root: node 3 (leaf), then node 2, finally root 1
Example 2 — Empty Tree
$
Input:
root = []
›
Output:
[]
💡 Note:
Empty tree returns empty array
Example 3 — Single Node
$
Input:
root = [1]
›
Output:
[1]
💡 Note:
Single node tree: only root to process
Constraints
- The number of nodes in the tree is in the range [0, 100]
- -100 ≤ Node.val ≤ 100
Visualization
Tap to expand
Understanding the Visualization
1
Input Tree
Binary tree with nodes [1,null,2,3]
2
Traversal Order
Visit left→right→root: 3, 2, then 1
3
Output Array
Collect node values: [3,2,1]
Key Takeaway
🎯 Key Insight: Postorder processes all children completely before touching the parent node
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code