int Height(TreeNode* root){
if(!root){
return 0;
}
int leftHeight=Height(root->left);
int rightHeight=Height(root->right);
if(leftHeight==-1||rightHeight==-1 || abs(leftHeight-rightHeight)>1){
return -1;
}
return max(leftHeight,rightHeight)+1;
}
bool isBalanced(TreeNode* root) {
if(root==nullptr) return true;
int height=Height(root);
return height!=-1;
}