Lintcode93 Balanced Binary Tree solution 题解
【题目描述】
Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.
给定一个二叉树,确定它是高度平衡的。对于这个问题,一棵高度平衡的二叉树的定义是:一棵二叉树中每个节点的两个子树的深度相差不会超过1。
【题目链接】
www.lintcode.com/en/problem/balanced-binary-tree/
【题目解析】
根据题意,平衡树的定义是两子树的深度差最大不超过1,显然使用递归进行分析较为方便。既然使用递归,那么接下来就需要分析递归调用的终止条件。NULL == root必然是其中一个终止条件,返回0;根据题意还需的另一终止条件应为「左右子树高度差大于1」,但对应此终止条件的返回值是多少?——INT_MAXorINT_MIN?可以传入参数中传入bool指针或者bool引用,并以此变量作为最终返回值。
【参考答案】
www.jiuzhang.com/solutions/balanced-binary-tree/
转载于:https://blog.51cto.com/13428907/1977086
Lintcode93 Balanced Binary Tree solution 题解相关推荐
- LeetCode 110 Balanced Binary Tree 平衡二叉树
LeetCode 110 Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this ...
- leetcode - Balanced Binary Tree
题目:Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, a ...
- leetCode 110. Balanced Binary Tree 平衡二叉树
110. Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, ...
- LeetCode 110. Balanced Binary Tree
LeetCode 110. Balanced Binary Tree 本博客参考自:http://www.cnblogs.com/grandyang/p/4045660.html Solution1: ...
- LeetCode 110 Balanced Binary Tree
LeetCode 110 Balanced Binary Tree Problem Description: 判断二叉树是不是平衡二叉树.所谓平衡二叉树,即每个节点的两个子树深度差的绝对值不超过1. ...
- 【leetcode】Balanced Binary Tree(middle)
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...
- LeetCode 110. 平衡二叉树(Balanced Binary Tree) 15
110. 平衡二叉树 110. Balanced Binary Tree 题目描述 给定一个二叉树,判断它是否是高度平衡的二叉树. 本题中,一棵高度平衡二叉树定义为: 一个二叉树每个节点的左右两个子树 ...
- [CareerCup] 4.1 Balanced Binary Tree 平衡二叉树
4.1 Implement a function to check if a binary tree is balanced. For the purposes of this question, a ...
- 平衡二叉树(Balanced Binary Tree)
平衡二叉树(Balanced Binary Tree) 平衡二叉树(Balanced Binary Tree)又称AVL树.AVL 树得名于它的发明者 G. M. Adelson-Velsky 和 E ...
最新文章
- java arraylist实现_java实现ArrayList基本功能
- 北风设计模式课程---里氏替换原则(Liskov Substitution Principle)
- 计算机模拟 博弈 善意,从两本奇书看人与人的重复博弈
- 基于阿里云ECS+ 宝塔面板(bt) + WordPress 搭建个人主页(以独立博客为例)
- android 多媒体文件信息,Android如何获取多媒体文件信息
- 有关数组知识点的小结
- OBJECT_ID(Transact-Sql)
- 关于CCS软件的Graph功能使用详解
- DPDK Release 21.05
- VMware上Ubuntu联网(NAT方式)
- Button控件更改背景和去掉边框
- Vulnhub靶机系列:SecTalks: BNE0x03 - Simple
- 毕业5年,我问遍了身边的大佬,总结了他们的学习方法
- 期刊模板-如何去除左下角的横线
- 浅谈Mesh组网与AC+AP组网区别
- mysql创建视图需注意_mysql视图创建注意事项
- 后序非递归遍历二叉树
- C语言习题——练习1
- 【2018 暑假计划】
- (一)移动端 Web 开发基础