首页
题库
面试
求职
学习
竞赛
More+
所有博客
搜索面经/职位/试题/公司
搜索
我要招人
去企业版
登录 / 注册
首页
>
试题广场
>
二叉树层序遍历 ii
[编程题]二叉树层序遍历 ii
热度指数:16109
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32M,其他语言64M
算法知识视频讲解
给定一个二叉树,返回该二叉树由底层到顶层的层序遍历,(从左向右,从叶子节点到根节点,一层一层的遍历)
例如:
给定的二叉树是
{3,9,20,#,#,15,7},
3 / \ 9 20 / \ 15 7
该二叉树由底层到顶层层序遍历的结果是
[[15,7],[9,20],[3]]
示例1
输入
{1,#,2}
输出
[[2],[1]]
说明:本题目包含复杂数据结构TreeNode,
点此查看相关信息
马上挑战
算法知识视频讲解
提交运行
算法知识视频讲解
添加笔记
求解答(4)
邀请回答
收藏(57)
分享
提交结果有问题?
107个回答
7篇题解
开通博客
jing_zhong
发表于 2021-09-01 10:05:22
题目描述:给定一个二叉树,返回该二叉树由底层到顶层的层序遍历,(从左向右,从叶子节点到根节点,一层一层的遍历)例如:给定的二叉树是{3,9,20,#,#,15,7},该二叉树由底层到顶层层序遍历的结果是 [[15,7],[9,20],[3]]示例1:
展开全文
一叶浮尘
发表于 2020-04-04 18:48:37
给定一个二叉树,返回该二叉树由底层到顶层的层序遍历,(从左向右,从叶子节点到根节点,一层一层的遍历)例如:给定的二叉树是{3,9,20,#,#,15,7},很简单,反转一下就行啊。 /** * Definition for binary tree * public class TreeNode
展开全文
FLOYD20191121155229
发表于 2024-09-24 11:42:22
/** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ class Solution { public: /** *
展开全文
O-Precedence
发表于 2021-09-08 12:31:38
正常层次遍历步骤,然后把结果reverse一下 import java.util.*; /* * public class TreeNode { * int val = 0; * TreeNode left = null; * TreeNode right = null; *
展开全文
华科不平凡
发表于 2020-08-21 21:15:44
利用递归的特性来实现: class Solution { public: /** * * @param root TreeNode类 * @return int整型vector<vector<>> */ vector&l
展开全文
我是嫩叠
发表于 2024-09-30 21:53:22
/** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ class Solution { public: /** * * @
展开全文
ivansli
发表于 2021-04-21 11:51:10
先分层遍历,再对结果进行翻转 func levelOrderBottom( root *TreeNode ) [][]int { // write code here if root == nil { return nil } ret := make
展开全文
问题信息
树
难度:
107条回答
57收藏
23044浏览
热门推荐
通过挑战的用户
查看代码
牛客61312...
2022-09-11 16:54:01
落霞与孤鹜齐飞ccc
2022-09-03 21:53:49
竹君20190...
2022-08-25 19:52:49
牛客84407...
2022-08-21 18:18:28
Varus20...
2022-08-20 14:41:40
相关试题
《绝地求生》中,每局游戏最多有多少...
游戏常识
评论
(1)
下面关于 Java 中 List ...
Java
评论
(1)
动态餐厅定价需要实时显示,延迟较低...
大模型开发
评论
(1)
以下Verilog代码描述了两个同...
Verilog
评论
(1)
以下使用生成器的数据管道代码中,若...
Python
评论
(1)
二叉树层序遍历 ii
扫描二维码,关注牛客网
意见反馈
下载牛客APP,随时随地刷题
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]]