Easy c++ solution using recurence relation


#1

int height(TreeNode* root){
if(root==NULL){
return -1;
}
else{
return 1+max(height(root->left),height(root->right));
}
}
int Solution::isBalanced(TreeNode* root) {
if(root==NULL){
return 1;
}
if(isBalanced(root->left) && isBalanced(root->right)){
if(abs(height(root->left)-height(root->right)) <=1){
return 1;
}
else{
return 0;
}
}
return 0;
}