bool IsBalanced(BinaryTreeNode* pRoot,int* pDepth)
{
if(pRoot==nullptr)
{
*pDepth=0;
return true;
}
int left,right;
if(IsBalanced(pRoot->m_pLeft,&left)&&IsBalanced(pRoot->m_pRight))
{
int diff=left-right;
if(diff<=1&&diff>-1)
{
*pDepth=1+(left>right?left?right);
return true;
}
}
return false;
}
判断平衡二叉树
最新推荐文章于 2022-07-01 17:03:31 发布