给定一个二叉树,返回该二叉树由底层到顶层的层序遍历,(从左向右,从叶子节点到根节点,一层一层的遍历) 例如: 给定的二叉树是{3,9,20,#,#,15,7}, 3 \ 9 20 \ 15 7 该二叉树由底层到顶层层序遍历的结果是 [[15,7],[9,20],[3]]
示例1
输入
{1,#,2}
输出
[[2],[1]]
加载中...
import java.util.*; /* * public class TreeNode { * int val = 0; * TreeNode left = null; * TreeNode right = null; * } */ public class Solution { /** * * @param root TreeNode类 * @return int整型ArrayList
> */ public ArrayList
> levelOrderBottom (TreeNode root) { // write code here } }
/** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ class Solution { public: /** * * @param root TreeNode类 * @return int整型vector
> */ vector
> levelOrderBottom(TreeNode* root) { // write code here } };
# class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None # # # @param root TreeNode类 # @return int整型二维数组 # class Solution: def levelOrderBottom(self , root ): # write code here
/* * function TreeNode(x) { * this.val = x; * this.left = null; * this.right = null; * } */ /** * * @param root TreeNode类 * @return int整型二维数组 */ function levelOrderBottom( root ) { // write code here } module.exports = { levelOrderBottom : levelOrderBottom };
# class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None # # # @param root TreeNode类 # @return int整型二维数组 # class Solution: def levelOrderBottom(self , root ): # write code here
package main import . "nc_tools" /* * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ /** * * @param root TreeNode类 * @return int整型二维数组 */ func levelOrderBottom( root *TreeNode ) [][]int { // write code here }
{1,#,2}
[[2],[1]]