#define max(a,b) (a>b?a:b)
int depth(struct TreeNode* root){
if(!root) return 0;
int left = depth(root->left);
if(left==-1) return -1;
int right = depth(root->right);
if(right==-1) return -1;
return abs(left-right) < 2 ? max(left,right) + 1 : -1;
}
bool isBalanced(struct TreeNode* root){
return depth(root)!=-1;
}
int height(struct TreeNode* root) {
if (root == NULL) {
return 0;
} else {
return fmax(height(root->left), height(root->right)) + 1;
}
}
bool isBalanced(struct TreeNode* root) {
if (root == NULL) {
return true;
} else {
return abs(height(root->left)-height(root->right)) <= 1 && isBalanced(root->left) && isBalanced(root->right);
}
}