dsa · easy
Binary Tree Postorder Traversal
Return the **postorder** values of root: walk the left subtree, then the right subtree, then visit the node. Each node is [val, left, right] or None. An empty tree yields [].
Arguments
root— binary tree as nested [val, left, right] or None
Example
root = [1, None, [2, [3, None, None], None]].
Left of 1 is empty. Inside the right subtree, left of 2 is 3 (a leaf), right of 2 is empty, then visit 2, then visit 1. The values are [3, 2, 1].
Constraints
Number of nodes in [0, 100] -100 <= val <= 100 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [1, None, [2, [3, None, None], None]] Expected: [3,2,1]
Example 2
Input: None Expected: []