Given the root of a binary tree, return the postorder traversal of its nodes' values: traverse the left subtree, then the right subtree, then visit the node itself.
Given the root of a binary tree, return the postorder traversal of its nodes' values: traverse the left subtree, then the right subtree, then visit the node itself.
Example 1:
Input: {"root":[5,3,8,1,4,7,9]}
Output: [1,4,3,7,9,8,5]
Constraints:
The number of nodes in the tree is in the range [0,100].
−100≤Node.val≤100
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"root":[5,3,8,1,4,7,9]}
Put the root 5 on s1. Phase 1 builds root, right, left order on s2; reading s2 backwards is postorder.