Easy Understanding Java Solution


  • 0
    E
    public static int arrangeCoins(int n) {
            int sum = n;
            int i = 1;
            for (; sum >= i; i++) {
                sum -= i;
            }
            return i - 1;
    

  • 0
    Y

    It can be more concise:

    public int arrangeCoins(int n) {
        int i = 0;
        while (n > i) n -= ++i;
        return i;
    }
    

Log in to reply
 

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