Simple intuitive c++ solution


#1

int Height(TreeNode *A){
if(A==NULL){
return 0;
}

 int lh = Height(A->left);
 int rh = Height(A->right);
 return 1 + max(lh , rh);

}

int Solution::isBalanced(TreeNode* A) {

if(A==NULL){
    return 1;
}

int lh = Height(A->left);
int rh = Height(A->right);

if(abs(lh-rh) > 1){
    return 0;
}

return isBalanced(A->left) & isBalanced(A->right);

}


#2

@ Ankit-chand, your solution is pretty simple and intuitive , but it has worst case complexity of o(n^2), try passing the heights, by reference through the helper function to solve it in o(n), just a suggestion :slight_smile: