首页
题库
面试
求职
学习
竞赛
More+
所有博客
搜索面经/职位/试题/公司
搜索
我要招人
去企业版
登录 / 注册
首页
>
试题广场
>
判断二叉树是否为平衡二叉树
[编程题]判断二叉树是否为平衡二叉树
热度指数:21357
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32M,其他语言64M
算法知识视频讲解
本题要求判断给定的二叉树是否是平衡二叉树
平衡二叉树的性质为: 要么是一棵空树,要么任何一个节点的左右子树高度差的绝对值不超过 1。
一颗树的高度指的是树的根节点到所有节点的距离中的最大值。
示例1
输入
{1,#,2,#,3}
输出
false
示例2
输入
{2,1,3}
输出
true
说明:本题目包含复杂数据结构TreeNode,
点此查看相关信息
马上挑战
算法知识视频讲解
提交运行
算法知识视频讲解
添加笔记
求解答(8)
邀请回答
收藏(99)
分享
提交结果有问题?
0个回答
6篇题解
添加回答
这道题你会答吗?花几分钟告诉大家答案吧!
提交观点
问题信息
树
dfs
难度:
0条回答
99收藏
20134浏览
热门推荐
通过挑战的用户
查看代码
玛卡不巴卡
2023-02-21 11:17:45
小鬼头的小迷弟
2022-09-22 21:08:03
牛客38441...
2022-09-14 16:44:48
牛客61312...
2022-09-11 15:58:03
牛客84407...
2022-09-03 18:09:28
相关试题
回路
dfs
评论
(51)
利用回溯法求下列不等式的所有整数解...
dfs
评论
(10)
来自
乐视2017秋招开发工程...
分支限界法与回溯法的相同点是()
dfs
评论
(4)
来自
360公司2016研发工...
有同事不完成任务,影响力进度,你怎...
业务综合
评论
(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
package main import . "nc_tools" /* * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ /** * * @param root TreeNode类 * @return bool布尔型 */ func isBalanced( root *TreeNode ) bool { // write code here }
{1,#,2,#,3}
false
{2,1,3}
true