首页
题库
面试
求职
学习
竞赛
More+
所有博客
搜索面经/职位/试题/公司
搜索
我要招人
去企业版
登录 / 注册
首页
>
试题广场
>
平衡树判定
[编程题]平衡树判定
热度指数:17
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32M,其他语言64M
算法知识视频讲解
实现一个函数检查一棵树是否平衡。对于这个问题而言,
平衡指的是这棵树任意两个叶子结点到根结点的距离之差不大于
1
示例1
输入
{1,2,3,#,#,4,#,#,5}
输出
false
说明
样例树形状
1
/ \
2 3
/
4
\
5
说明:本题目包含复杂数据结构TreeNode,
点此查看相关信息
马上挑战
算法知识视频讲解
提交运行
算法知识视频讲解
添加笔记
求解答(0)
邀请回答
收藏(3)
分享
纠错
提交结果有问题?
2个回答
0篇题解
开通博客
暂无题解
问题信息
算法工程师
2020
映客
上传者:
小小
难度:
2条回答
3收藏
1917浏览
热门推荐
通过挑战的用户
NoCoinC...
2022-07-12 21:04:02
空城深处,住着空心、
2022-07-07 15:09:30
牛客45720...
2022-05-11 16:38:23
一条固执的fish
2022-04-21 21:55:39
牛客14612...
2022-03-11 21:38:09
相关试题
假定所有变量均已正确定义,则下列程...
算法工程师
映客
2020
评论
(0)
如果你想列出当前目录以及子目录下所...
算法工程师
映客
2020
评论
(2)
看图回答
判断推理
2020
人力资源
安永
审计
税务服务
风险管理
管理咨询
行政管理
评论
(3)
来自
职能类模拟题2
若存在一颗平衡二叉树,其所有非叶结...
树
评论
(1)
在超网络中,生成子网络参数的过程通...
机器学习
评论
(1)
平衡树判定
扫描二维码,关注牛客网
意见反馈
下载牛客APP,随时随地刷题
import java.util.*; /* * public class TreeNode { * int val = 0; * TreeNode left = null; * TreeNode right = null; * } */ public class Solution { /** * * @param root TreeNode类 树的根节点 * @return bool布尔型 */ public boolean isBalanced (TreeNode root) { // write code here } }
/** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ class Solution { public: /** * * @param root TreeNode类 树的根节点 * @return bool布尔型 */ bool isBalanced(TreeNode* root) { // write code here } };
# class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None # # # @param root TreeNode类 树的根节点 # @return bool布尔型 # class Solution: def isBalanced(self , root ): # write code here
/* * function TreeNode(x) { * this.val = x; * this.left = null; * this.right = null; * } */ /** * * @param root TreeNode类 树的根节点 * @return bool布尔型 */ function isBalanced( root ) { // write code here } module.exports = { isBalanced : isBalanced };
# class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None # # # @param root TreeNode类 树的根节点 # @return bool布尔型 # class Solution: def isBalanced(self , root ): # write code here
{1,2,3,#,#,4,#,#,5}
false