Problems/216. Binary Tree Postorder Traversal

216. Binary Tree Postorder Traversal

EasyBinary Tree

Given the root of a binary tree, visit and collect its node values using a postorder traversal strategy (recursively traversing the left subtree, then traversing the right subtree, and finally visiting the current node).

Example 1
Input: root = [4, 2, 6, 1, 3, 5, 7]
Output: [1, 3, 2, 5, 7, 6, 4]
We traverse the left subtree first: node 1 is visited, then node 3, then node 2. Next, we traverse the right subtree: node 5, then node 7, then node 6. Finally, we visit the root node 4.
Example 2
Input: root = [1, null, 2, null, 3]
Output: [3, 2, 1]
We recursively traverse the right subtree to the deepest node: node 3 is visited, then node 2 is visited, and finally the root node 1 is visited.
Example 3
Input: root = [1]
Output: [1]
Only the root node is present, so we visit the root value 1 and return.
Visualizer

Visualizer will appear here