Balanced Binary Tree
来源:互联网 发布:安卓手机变win7软件 编辑:程序博客网 时间:2024/06/18 16:29
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.
class Solution {public: bool is_balanced = true; int checkHieght(TreeNode *root) { int lh = 0, rh = 0; if(root == NULL || is_balanced == false) return 0; if(root->left != NULL && is_balanced == true) lh = checkHieght(root->left) + 1; if(root->right != NULL && is_balanced == true) rh = checkHieght(root->right) + 1; if(abs(lh - rh) > 1) is_balanced = false; return lh > rh ? lh : rh; } bool isBalanced(TreeNode *root) { checkHieght(root); return is_balanced; }};
0 0
- Balanced binary tree 扩展
- LeetCode: Balanced Binary Tree
- [LeetCode]Balanced Binary Tree
- LeetCode Balanced Binary Tree
- [Leetcode] Balanced Binary Tree
- LeetCode : Balanced Binary Tree
- LeetCode Balanced Binary Tree
- [LeetCode] Balanced Binary Tree
- Balanced Binary Tree
- Balanced Binary Tree
- 【leetcode】Balanced Binary Tree
- Balanced Binary Tree
- [LeetCode]Balanced Binary Tree
- Balanced Binary Tree
- Balanced Binary Tree
- [LeetCode] Balanced Binary Tree
- [Leetcode]Balanced Binary Tree
- [leetcode]Balanced Binary Tree
- Springmvc构造RESTful详细讲解
- USB驱动程序框架搭建
- 在iOS的webview 上画一条1px的线
- Java Web 程序的目录结构
- C++获取文件字节数
- Balanced Binary Tree
- 黑马程序员_继承
- 若要针对 .NET Framework 4.0 或更高版本进行编译,则提供程序选项中“compile
- linux tree命令详解---linux以树状图逐级列出目录的内容命令
- Android源码检索
- 在VS2008中使用Qt编程——学习笔记1
- 浮点数精度整理
- html模板,根据链接调用页面展示
- linux stat命令参数及用法详解---linux显示inode节点内容命令