JAVA | Self-Explanatory | Just while loop | no algorithm


  • 0
    S
    public class Solution {
        public int arrangeCoins(int n) {
            
            int staircase=1;
            int count = 0;
            while(staircase <= n){
                n = n-staircase;
                count++;
                staircase++;
            }        
            return count;
        }
    }
    

Log in to reply
 

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