Given the root of a binary tree, return the bottom-up level order traversal of its node values: each level read from left to right, starting with the deepest level and ending with the root.
Given the root of a binary tree, return the bottom-up level order traversal of its node values: each level read from left to right, starting with the deepest level and ending with the root.
Example 1:
Input: {"root":[3,9,20,null,null,15,7]}
Output: [[15,7],[9,20],[3]]
Constraints:
The number of nodes in the tree is in the range [0,2000].
−1000≤Node.val≤1000
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"root":[3,9,20,null,null,15,7]}
Make res a deque so each finished level can be added to its front in O(1).
d0d1d23920157
queue
front
empty
level
[]
res
each finished level is inserted at the front (top)