leetcode/110.c
2024-09-08 14:39:20 +08:00

29 lines
518 B
C

#include "include/TreeNode.h"
#include <math.h>
#include <stdbool.h>
#include <stdlib.h>
int maxHight(struct TreeNode *root)
{
if (!root)
return 0;
return fmax(maxHight(root->left), maxHight(root->right)) + 1;
}
bool isBalanced(struct TreeNode *root)
{
if (!root)
return true;
if (!isBalanced(root->left))
return false;
if (!isBalanced(root->right))
return false;
return abs(maxHight(root->left) - maxHight(root->right)) <= 1;
}
int main()
{
return 0;
}