Binary Tree Postorder Traversal
Tree
easy
Score: 20
Given the root
of a binary tree, return the postorder traversal of its nodes’ values.
Class TreeNode:
val (int)
left (TreeNode)
right (TreeNode)
Input Format
First Parameter - TreeNode root
Output Format
Return the array of values of nodes in postorder sequence
Example 1:
Input:
1 2 3 7 4 null 8
Output:
7 4 2 8 3 1
Example 2:
Input:
1 null 2 null 5 3 8 null 4
Output:
4 3 8 5 2 1
Constraints
- The number of the nodes in the tree is in the range [0, 100].
- -100 <= Node.val <= 100
- Expected Time Complexity: O(n)
- Expected Space Complexity: O(1)