Easy understand C++


  • 0
    B
    bool isBalanced(TreeNode* root) {
        if(root == NULL)
            return true;
        int leftdeep = deepofBinary(root->left);
        int rightdeep = deepofBinary(root->right);
        if(leftdeep-rightdeep > 1 || rightdeep-leftdeep > 1)
            return false;
        else
            return isBalanced(root->left) && isBalanced(root->right);
    }
    int deepofBinary(TreeNode* root)
    {
        if(root == NULL)
            return 0;
        int left = 1 + deepofBinary(root->left);
        int right = 1 + deepofBinary(root->right);
        return left>right?left:right;
    }

  • 0
    H

    Therr are 2 recursive functions?


Log in to reply
 

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