Posted on

Description

Submission

class Solution {
public:
    int arrangeCoins(int n) {
        return (int) (sqrt(1 + 8 * (long long)n) - 1) / 2;
    }
};


// (1 + x) * x / 2 = n;
// (1 + x) * x = 2 * n
// x^2 + x - 2*n = 0;

Leave a Reply

Your email address will not be published. Required fields are marked *