Bottom-Up Level Order Traversal
List a tree's levels from the deepest one up to the root.
The problem
Implement Solution.levelOrderBottom(root). root is the root TreeNode of a binary tree, or None for an empty tree; each node has val, left and right. Return one inner list per level, starting with the deepest level and ending with the root. Inside each level, keep the values in left-to-right order. Return [] for an empty tree. Trees are written in level order with None for a missing child. For [3, 9, 20, None, None, 15, 7] return [[15, 7], [9, 20], [3]]. Constraints: the tree has 0 to 2,000 nodes; values are integers from -1,000 to 1,000. Do not change the tree.
Starter code
class Solution:
def levelOrderBottom(self, root):
passPublic examples
root = [3, 9, 20, None, None, 15, 7]gives[[15, 7], [9, 20], [3]]root = [1, 2, 3]gives[[2, 3], [1]]root = [-9]gives[[-9]]
Solving it in the practice book needs an active paid plan.
Open it in the practice bookOne thought at a time.
