Balanced Binary Tree
来源:互联网 发布:逸晗网络视频编辑 编辑:程序博客网 时间:2024/05/19 02:43
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 (depth(root) == -1) return false; return true;}int depth(TreeNode *node){ if (!node) return 0; int leftDepth = helper(node->left); int rightDepth = helper(node->right); if (leftDepth == -1 || rightDepth == -1) return -1; if (abs(leftDepth - rightDepth) > 1) return -1; return leftDepth < rightDepth ? rightDepth + 1 : leftDepth + 1;}
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
- ZOJ-3311
- Redis 发布/订阅机制原理分析
- kvc和kvo
- 利用javascript动态创建表格<!--进阶-->
- http://pan.baidu.com/share/link?shareid=137160&uk=3743344153
- Balanced Binary Tree
- USACO:test文件提交方法
- Qemu下u-Boot + Kernel + rootfs完整启动移植
- 你误把饥渴当成了爱情
- 纯CSS实现3D翻牌效果
- 《高效学习OpenGL》 之 执行多个显示列表 glListBase(), glCallLists()
- JavaScript Source Map
- 葬花吟
- android软件开发QQ群