解题思路:
(1)递归判断左右子树的高度差的绝对值
class Solution {
public:
bool IsBalanced_Solution(TreeNode* pRoot) {
bool tag = true;
height(pRoot,tag);
return tag;
}
int height(TreeNode* root,bool &tag) {
if(root==NULL) return -1;
int l = height(root->left,tag);
int r = height(root->right,tag);
if(abs(l-r)>1) tag=false;
return max(l,r)+1;
}
};