C# - O(1) - root of quadratic equation


  • 0
    K

    The solution is positive root of the quadratic equation x^2 + x - 2n = 0

    public int ArrangeCoins(int n) {
    return (int)(-1 + (long)Math.Sqrt(1 + ((long)8 * n))) / 2;
    }


Log in to reply
 

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