Binary Tree Level Order Traversal
Problem statement
Return the tree values level by level from top to bottom. Within each level, list nodes from left to right.
Function
levelOrder(root: TreeNode) → int[][]Examples
Example 1
root = [3,9,20,null,null,15,7]return = [[3],[9,20],[15,7]]The root forms level zero, followed by its children and then the final two grandchildren.
Constraints
- The tree contains between
0and10000nodes. - Node values fit in a signed 32-bit integer.