def level_order(root):
    """层序遍历二叉树。

    :param root:
    :return:
    example :
        1
       /\
      2  3
    will return:
    [
     [1],
     [2,3]
    ]
    """
    levels = []
    if not root:
        return []
    cur_level = list()
    cur_level.append(root)
    while len(cur_level) > 0:
        cur_eles = []
        next_level = []
        for node in cur_level:
            cur_eles.append(node.val)
            if node.left:
                next_level.append(node.left)
            if node.right:
                next_level.append(node.right)
        levels.append(cur_eles)
        cur_level = next_level
    return levels