← 返回 google 的题目列表Binary Tree Level Order Traversal
类型:online_judge
Given the root of a binary tree, return the values of its nodes level by level, from left to right. Nodes at the same depth must appear in the same inner list.
Input Format
The standard input is a level-order array representation of a binary tree:
An integer represents a node value.
null represents a missing node.
Trailing null values may be omitted.
Output Format
Print a two-dimensional array where each inner array contains the values at one tree level.
Example 1
Input:
[3,9,20,null,null,15,7]
Output:
[[3],[9,20],[15,7]]
Example 2
Input:
[1]
Output:
[[1]]
Example 3
Input:
[]
Output:
[]
Constraints
0 <= n <= 2000
-1000 <= Node.val <= 1000
Example
Input
[3,9,20,null,null,15,7]
Output
[[3],[9,20],[15,7]]