Loading...
Given the root of a binary tree, return the level-order traversal of its node values: one array per depth level, from the root level downward, with each level's values listed left to right.
The empty tree yields an empty result.
Your function receives root as a TreeNode (or as null for the empty tree). The node type is provided for you, with val, left, and right fields.
The examples below write the tree as its level-order traversal, where null marks a missing child of a listed node and trailing nulls are omitted. That is only how the input is displayed; the decoding is done for you.
Node.val ≤10003 is the root; 9 and 20 form the second level; 15 and 7 are the children of 20 and form the third level.
Click "Run" to test with sample cases or "Submit" to run all tests.