107. Binary Tree Level Order Traversal II
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 7return its bottom-up level order traversal as:
[
[15,7],
[9,20],
[3]
]解法
层序遍历
层序遍历,将每层的结果保存到列表,最后反转列表。
举个例子:
递归解法
TODO: 深度优先、广度优先
any 的用法
如果测试用例为 [],那么:
所以此处必须使用 any。
Last updated
Was this helpful?