```
#include <math.h>
bool isBalanced(struct TreeNode* root) {
if (root == NULL) return 1;
else if (abs(max(root->right) - max(root->left)) > 1 ) return 0;
else return isBalanced(root->right) && isBalanced(root->left);
}
int max(struct TreeNode* node) {
if (node == NULL) return 0;
int r = 0, l = 0;
r = max(node->right) +1;
l = max(node->left) + 1;
return (r > l) ? r : l;
}
```