Balanced Binary Tree
来源:互联网 发布:java.util. 无法引入 编辑:程序博客网 时间:2024/06/13 22:51
一、题目要求
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.
二、代码实现
bool isBalanced(TreeNode* root) { if(root==NULL) return true; int left=maxDepth(root->left); int right=maxDepth(root->right); if(abs(left-right)>1) return false; return isBalanced(root->left)&&isBalanced(root->right); } int maxDepth(TreeNode* root) { if(root==NULL) return 0; int left=1+maxDepth(root->left); int right=1+maxDepth(root->right); return left>right?left:right; }
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
- D3D的绘制函数总结
- Scala中Dependency Injection
- Linux 常用命令总结
- 9.19 搭服务器折腾centos
- Warfire 战火 1.0 开发小记
- Balanced Binary Tree
- Sliding Window Maximum
- android studio的源文件编码和字符串比较
- Path Sum
- Android中的ClassLoader与dex文件加密实现分析
- 游戏中的帧率控制
- 文章标题
- HDU 2199 Can you solve this equation?
- DVB-S info