Simple recursive c++ solution


  • 0
    P
    int depth(TreeNode* root) {
        return root?max(depth(root->left),depth(root->right))+1:0;
    }
    bool isBalanced(TreeNode* root) {
        return root?abs(depth(root->left)-depth(root->right))<=1&&isBalanced(root->left)&&isBalanced(root->right):true;
    }

Log in to reply
 

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