Simplest C++ Solution (Logical)


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