平衡二叉树
来源:互联网 发布:原始原素 知乎 编辑:程序博客网 时间:2024/06/07 01:50
题目描述
输入一棵二叉树,判断该二叉树是否是平衡二叉树。
//TreeDepth是前面一道题的函数;IsBalanced_Solution里的return语句,又涉及更早的一道题(树的子结构)class Solution {public: bool IsBalanced_Solution(TreeNode* pRoot) { if(!pRoot) return true; return IsBalanced_Solution(pRoot->left)&&IsBalanced_Solution(pRoot->right) &&abs(TreeDepth(pRoot->left)-TreeDepth(pRoot->right))<=1; } int TreeDepth(TreeNode* pRoot) { if(!pRoot) return 0; return max(TreeDepth(pRoot->left),TreeDepth(pRoot->right))+1; }};
0 0
- 平衡二叉树平衡法则
- 二叉树--二叉平衡树
- 平衡二叉树的
- 平衡二叉树
- 平衡二叉树
- 平衡二叉树
- 平衡二叉树
- 平衡二叉查找树
- 平衡二叉树 详解
- 平衡二叉树
- 平衡二叉树
- AVL 平衡二叉树
- 平衡二叉树
- 平衡二叉树-红黑树
- 平衡二叉树
- 平衡二叉树
- 平衡二叉树
- 平衡二叉树
- arcgis拓扑处理
- easyui-tree实现所有节点勾选、同步勾选
- hdu 2017 字符串统计
- 线程池调整真的很重要
- 素数打表
- 平衡二叉树
- 监控软件
- fusioncharts在asp.net中的应用
- JavaScript中,函数也是一个变量,即var XXX。典型例子
- git 命令步骤
- JDBC连接池
- 微信公众号开发中遇到的问题——模板信息,自定义回复,一次请求多次相应
- Qt之图形(QPainter的基本绘图)
- Java多线程/并发08、中断线程 interrupt()