Easy Understanding Java Solution with only one while loop


  • 0

    Here is the code:

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

Log in to reply
 

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