Binary Tree Postorder Traversal
Given the root of a binary tree, return the postorder traversal of its nodes' values.
Follow up: Recursive solution is trivial, could you do it iteratively?
Example 1
1
\
2
/
3Input
root = [1,null,2,3]Output
[3,2,1]Postorder traversal visits the left subtree, then the right subtree, then the root, producing
[3, 2, 1].Example 2
1
/ \
2 3
/ \ \
4 5 8
/ \ /
6 7 9Input
root = [1,2,3,4,5,null,8,null,null,6,7,9]Output
[4,6,7,5,2,9,8,3,1]Visiting each subtree in postorder produces
[4, 6, 7, 5, 2, 9, 8, 3, 1].Constraints
- The number of the nodes in the tree is in the range
[0, 100]. -100 <= Node.val <= 100