题目描述
输入一棵二叉树,判断该二叉树是否是平衡二叉树。
class Solution {
public:
int Depth(TreeNode* root)
{
if(!root)
return 0;
else
return 1+max(Depth(root->left),Depth(root->right));
}
bool IsBalanced_Solution(TreeNode* pRoot)
{
if(!pRoot)
return true;
return (abs(Depth(pRoot->left)-Depth(pRoot->right))<=1)&&IsBalanced_Solution(pRoot->left)&&IsBalanced_Solution(pRoot->right);
}
};