Regular high school formula no fancy C++ code.


  • 0
    S
    class Solution {
    public:
        int arrangeCoins(int n) {
     //Use the regular formula for ax^2+bx+c=0; where c=2*n,a=1,b=1.
            double xy=4*(double)2*n;
            double x=(-1+sqrt(1+xy))/2;
            return x;
        }
    };
    

Log in to reply
 

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