CODE 23: Balanced Binary Tree
来源:互联网 发布:fp growth算法 编辑:程序博客网 时间:2024/06/01 20:27
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 ofevery node never differ by more than 1.
public boolean isBalanced(TreeNode root) {// Start typing your Java solution below// DO NOT write main() functionif (null == root) {return true;}return checkBalanced(root) != -1;}public int checkBalanced(TreeNode root) {if (null == root) {return 0;}int left = checkBalanced(root.left);int right = checkBalanced(root.right);if (left == -1 || right == -1) {return -1;}if (Math.abs(left - right) > 1) {return -1;} else {return Math.max(left, right) + 1;}}
- CODE 23: Balanced Binary Tree
- [leet code] Balanced Binary Tree
- [leet code] Balanced Binary Tree
- balanced-binary-tree Java code
- leetcode 日经贴,python code -Balanced Binary Tree
- Leet Code OJ 110. Balanced Binary Tree [Difficulty: Easy]
- 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
- uva 409 Excuses, Excuses!
- 大三了
- [各种面试题] 非负大整数加法
- 操作系统重装,如何恢复oracle数据库
- mysql导入sql语句命令
- CODE 23: Balanced Binary Tree
- makefile 中的 wildcard,foreach 与 patsubst 函数 .
- C#.NET学习笔记11,12---布尔表达式2组合,if语句
- JQuery浮动层
- 多线程之交通灯系统
- MFC多线程控制进度条
- (转)Android通过URL获取网络数据
- HDU 4602 Partition
- 内存管理概述、内存分配与释放、地址映射机制