Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).
For example:
Given binary tree [3,9,20,null,null,15,7]
,
3 / \ 9 20 / \ 15 7
return its bottom-up level order traversal as:
[ [15,7], [9,20], [3] ]
方法一:递归 + 广搜
# -*- coding:utf-8 -*-
__author__ = 'yangxin_ryan'
"""
Solutions:
这里要求的返回数据是从二叉树的最后一层从左到右返回集合。
那么我们可以将问题转化为先广搜(宽搜),然后将遍历的结果逆转返回即可。
其中分层遍历使用递归方式即可。
推演过程为
[]
[[]]
[[3]]
[[3],[]]
[[3],[9]]
[[3],[9,20]]
[[3],[9,20],[]]
[[3],[9,20],[15]]
[[3],[9,20],[15,7]]
[[15,7],[9,20],[3]]
"""
class BinaryTreeLevelOrderTrav