boolean isBanalced = true;
public boolean IsBalanced_Solution(TreeNode root) {
if(root == null){
return true;
}
getHeight(root);
return isBanalced;
}
private int getHeight(TreeNode node){
if(node == null){
return 0;
}
int left = getHeight(node.left);
int right = getHeight(node.right);
if(Math.abs(right - left) > 1){
isBanalced = false;
}
return Math.max(left, right)+1;
}
}