int getdepth(TreeNode* pRoot)
{
if (pRoot == NULL)
{
return 0;
}
//1 + getdepth();
//递归计算树的深度
return max(1 + getdepth(pRoot->left), 1 + getdepth(pRoot->right));
}
bool IsBalanced_Solution(TreeNode* pRoot)
{
if (pRoot == NULL)
{
return true;
}
int left_depth = getdepth(pRoot->left);
int right_depth = getdepth(pRoot->right);
if (left_depth > right_depth + 1 || left_depth + 1 < right_depth)
{
return false;
}
else
{
return IsBalanced_Solution(pRoot->left) && IsBalanced_Solution(pRoot->right);
}
}