Problem · Tree

Binary Tree Level Order Traversal

Learn this problem
MediumAtlassian logoAtlassianFULLTIMEOA

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 0 and 10000 nodes.
  • Node values fit in a signed 32-bit integer.

More Atlassian problems

drafts saved locally
public int[][] levelOrder(TreeNode root) {
  // Write your code here.
}
root[3,9,20,null,null,15,7]
expected[[3],[9,20],[15,7]]
checking account