题解 | #判断是不是平衡二叉树#
判断是不是平衡二叉树
https://www.nowcoder.com/practice/8b3b95850edb4115918ecebdf1b4d222
/**
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param pRoot TreeNode类
* @return bool布尔型
*/
bool judge = true;
int high_tree(struct TreeNode* root){
if(root==NULL)return 0;
int h1 = high_tree(root->left);
int h2 = high_tree(root->right);
if(abs(h1-h2)>1)judge=false;
return h1>h2?h1+1:h2+1;
}
bool IsBalanced_Solution(struct TreeNode* pRoot ) {
// write code here
high_tree(pRoot);
return judge;
}


