//是否是平衡二叉树
int IsBalanceTree(bnode *root)
{
if(root == NULL)
{
return 1;
}
int leftDepth = GetDepth(root->pLeft);
int rightDepth = GetDepth(root->pRight);
int distance = leftDepth - rightDepth;
if(distance > 1 || distance < -1)
{
return 0;
}
return IsBalanceTree(root->pLeft) && IsBalanceTree(root->pRight);
}
【二叉树】判断一棵二叉树是否是平衡二叉树
最新推荐文章于 2021-03-03 22:06:14 发布