C866a622444a7c18d1e7748a1ed00e00
(难度Medium) Problem 102. Binary Tree Level Order Traversal(树元素归类)

Binary Tree Level Order Traversal

Difficulty

Medium

Description

Given a binary tree, return the _level order_ traversal of its nodes' values.
(ie, from left to right, level by level).

For example:
Given binary tree [3,9,20,null,null,15,7],

    3
   / \
  9  20
    /  \
   15   7

return its level order traversal as:

[
  [3],
  [9,20],
  [15,7]
]

题意

给定一个二叉树,要求将二叉树当中的元素按照在树当中的深度分类。最后返回一个vector> 类型的结果。这个vector当中,位置i存储的是深度为i的所有元素。

有一个条件是,需要保证同一层的元素从左往右排列。

top Created with Sketch.