LeetCode110——Balanced Binary Tree
来源:互联网 发布:阿里云防cc攻击 编辑:程序博客网 时间:2024/06/02 02:10
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.
难度系数:
容易
实现
int getDepth(TreeNode *root){ if (root == NULL) return 0; if (root->left == NULL && root->right == NULL) return 1; int leftd = getDepth(root->left); int rightd = getDepth(root->right); return leftd > rightd ? leftd + 1 : rightd + 1;}bool isBalanced(TreeNode *root) { if (root == NULL) return true; if (root->left == NULL && getDepth(root->right) <= 1) return true; if (root->right == NULL && getDepth(root->left) <= 1) return true; if ((getDepth(root->left) - getDepth(root->right)) > 1 || (getDepth(root->right) - getDepth(root->left)) > 1) { return false; } return isBalanced(root->left) && isBalanced(root->right);}
0 0
- LeetCode110—Balanced Binary Tree
- LeetCode110——Balanced Binary Tree
- LeetCode110 - Balanced Binary Tree
- LeetCode110-Balanced Binary Tree
- leetcode110---Balanced Binary Tree
- LeetCode110:Balanced Binary Tree
- LeetCode110. Balanced Binary Tree
- leetcode110~Balanced Binary Tree
- leetcode110. Balanced Binary Tree
- LeetCode110 Balanced Binary Tree
- leetcode110 Balanced Binary Tree
- Leetcode110. Balanced Binary Tree
- LeetCode110. Balanced Binary Tree
- LeetCode110.Balanced Binary Tree题解
- LeetCode——Balanced Binary Tree
- leetcode——Balanced Binary Tree
- Balanced Binary Tree——LeetCode
- LeetCode——Balanced Binary Tree
- Junit4.X使用教程
- BZOJ 2002 弹飞绵羊 Link-Cut-Tree(LCT)
- 区分现有的vc工程是有哪一版本的工具开发?
- 常用的正则表达式测试工具
- PLSQL:Exit Statement
- LeetCode110——Balanced Binary Tree
- 一,超猪聊技术----jdk对象序列化协议
- 撤销和闪回技术
- BZOJ大视野 1191: [HNOI2006]超级英雄Hero
- Core Animation 叠加
- javafX初探(滚动条)
- sharepoint 列表文件夹的基本操作(增、删、改、查)
- android Asynctask和handler的区别是什么?优缺点各是什么?能否同时并发100+asyncTask呢?
- 复制目标数据库