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、
bool isBalanced(TreeNode *root) {
if(!root) return true;
bool judge=true;
binaryLevel(root,judge);
return judge;
}
int binaryLevel(TreeNode* root,bool &judge)
{
if(!judge) return 0;
if(!root) return 0;
int left=binaryLevel(root->left,judge);
int right=binaryLevel(root->right,judge);
if(abs(left-right)<=1)
return left>=right?left+1:right+1;
else
{
judge=false;
return 0;
}
}