class Solution {
public:
bool isBalanced(TreeNode* root) {
if(!root)
{
return true;
}
else
{
return abs(deepth(root->left) - deepth(root->right)) <= 1 && isBalanced(root->left) && isBalanced(root->right);
}
}
int deepth(TreeNode *root)
{
if(!root)
{
return 0;
}
else
{
return max(deepth(root->left),deepth(root->right)) + 1;
}
}
};
leetcode每日一题第124天
最新推荐文章于 2024-07-20 22:34:59 发布