Lintcode93 Balanced Binary Tree solution 题解
来源:互联网 发布:黑社会网络2001 编辑:程序博客网 时间:2024/05/18 01:46
【题目描述】
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/
阅读全文
0 0
- Lintcode93 Balanced Binary Tree solution 题解
- [LeetCode] Balanced Binary Tree Solution
- LeetCode题解:Balanced Binary Tree
- LeetCode题解: Balanced Binary Tree
- leetcode Balanced Binary Tree 题解
- LeetCode题解:Balanced Binary Tree
- [LeetCode] Balanced Binary Tree 题解
- LeetCode110.Balanced Binary Tree题解
- LeetCode 题解(20): Balanced Binary Tree
- LeetCode题解——Balanced Binary Tree
- LeetCode题解-110-Balanced Binary Tree
- LeetCode 110. Balanced Binary Tree 题解
- LeetCode 110. Balanced Binary Tree 题解
- Lintcode7 Binary Tree Serialization solution 题解
- Lintcode66 Binary Tree Preorder Traversal solution 题解
- Lintcode67 Binary Tree Inorder Traversal solution 题解
- Lintcode68 Binary Tree Postorder Traversal solution 题解
- Lintcode95 Validate Binary Search Tree solution 题解
- Python pip安装包的问题记录
- 使聊天机器人的对话更有营养
- 数组操作(进阶)
- Struts提供的强大的HTML标签库总结
- H
- Lintcode93 Balanced Binary Tree solution 题解
- 如何去掉browserLinkSignalR功能、VS2013、VS2015
- Linux忘记 root密码的解决办法
- Datatable的值设置
- 2017 Multi-University Training Contest 1 1002. Balala Power!(贪心)
- iOS开发内购详细
- 在神经网络中weight decay、momentum、batch normalization各自意义
- 基于TensorFlow算法的物体识别API,将引发计算机视觉链式突破
- Ubuntu 下 apt-get 更新源推荐