easy java solution


  • 0
    S

    Just decrease the number deducting the iteration variable

    public int arrangeCoins(int n) {
           if(n==1) return 1;
           int count = 0;
           for(int i=1;i<=n;i++){
               if(n>=i) {
                   count++;
                   n -= i;
               }
           }
           return count;
       }

Log in to reply
 

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