110. Balanced Binary Tree
来源:互联网 发布:ipad应用网络连接失败 编辑:程序博客网 时间:2024/05/21 17:31
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.
判断是否是平衡二叉树
深度相差一:
1.所有子树的深度都相差不超过一
2.求子树的深度
public class Solution { /** * @param root: The root of binary tree. * @return: True if this Binary tree is Balanced, or false. */ public boolean isBalanced(TreeNode root) { if(root==null) return true; int left=depth(root.left); int right=depth(root.right); return Math.abs(left-right)<=1&&isBalanced(root.left)&&isBalanced(root.right); } public int depth(TreeNode root){ if(root==null) return 0; return Math.max(depth(root.left),depth(root.right))+1; } }
0 0
- 110.Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- Linux下的进程间通信
- Android 动态监听网络变化
- Java 8新特性
- 索引
- 使Eclipse或AndroidStudio的代码模板自动生成类名和方法名
- 110. Balanced Binary Tree
- Promise原理分析一
- ZigZag Conversion
- 按系列罗列Linux的发行版,并描述不同发行版之间的联系与区别。
- android:launchMode 启动模式
- JAVA进阶3.2——Equals方法(2)
- Shell 初始化文件和注销文件
- Web版CRUD开发流程实例(一)
- P\NP\NPC(Non-Deterministic Polynomial Complete Problem)