题目描述:
输入一棵二叉树,判断该二叉树是否是平衡二叉树。
题目链接:
剑指offer55.2
public class Solution {
boolean isBalanced = true;
public boolean IsBalanced_Solution(TreeNode root) {
getDepth(root);
return isBalanced;
}
private int getDepth(TreeNode root) {
if(root == null){
return 0;
}
int lft = getDepth(root.left);
int right = getDepth(root.right);
if(Math.abs(lft-right)>1){
isBalanced = false;
}
return Math.max(lft,right)+1;
}
}