Binary Tree Level Order
Return the values of a binary tree level by level, from left to right.
The problem
Implement Solution.levelOrder(root). root is the root TreeNode of a binary tree, or None for an empty tree; each node has val, left and right. Return a list with one inner list per depth, starting from the root, where each inner list holds that depth's values from left to right. Return [] for an empty tree.
Starter code
class Solution:
def levelOrder(self, root):
passPublic examples
root = [3, 9, 20, None, None, 15, 7]gives[[3], [9, 20], [15, 7]]root = [-7]gives[[-7]]root = [1, 2, 3]gives[[1], [2, 3]]
Solving it in the practice book needs an active paid plan.
Open it in the practice bookOne thought at a time.
