Binary Tree Postorder Traversal
Given the root of a binary tree, return the postorder traversal of its node values: left subtree, right subtree, and the node itself last.
Open on LeetCode ↗Intuition
Postorder visits a node only after both subtrees are finished — children first, parent last. It's the order you'd delete a tree safely, or compute anything where a node's answer depends on its children's answers.
Approach
Visit after both children
Move the append below the two recursive calls: recurse left, recurse right, then record node.val. The node waits until everything beneath it is done — the root is always the very last value in the output.
The 'answers flow upward' order
Postorder is the shape of almost every tree DP: size of subtree, height, 'is balanced', evaluating an expression tree. Whenever a parent needs its children's results first, you're writing postorder whether you call it that or not.
Iterative trick
Do a modified preorder (node, right, left) with a stack and reverse the result at the end — far simpler than tracking whether each node's children are done.
Solution & live demo
Edge cases
Base case → empty list.
Output is left leaf, right leaf, root — parent strictly after children.
Recursion unwinds from the bottom, so the deepest node is emitted first and the root last.