straight forward c++ solution


  • 0
    S

    int NodeHeight(TreeNode* node){
    if(!node) return 0;
    return max(NodeHeight(node->left)+1,NodeHeight(node->right)+1);
    }
    bool isBalanced(TreeNode* root) {
    if(!root) return true;
    return abs(NodeHeight(root->left)-NodeHeight(root->right))<=1 && isBalanced(root->left) && isBalanced(root->right);
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.