class Solution {
public:
bool isBalanced(TreeNode* root)
{
if(root==NULL)
{
return true;
}
if(abs(height(root->left)-height(root->right))<=1)
{
return isBalanced(root->left)&&isBalanced(root->right);
}
else
{
return false;
}
}
int height(TreeNode* root)
{
if(root==NULL)
{
return 0;
}
else
{
return max(height(root->left),height(root->right))+1;
}
}
};
110---平衡二叉树 难度:简单
最新推荐文章于 2021-02-12 02:06:04 发布