美文网首页
441. Arranging Coins

441. Arranging Coins

作者: hyhchaos | 来源:发表于2016-12-26 20:28 被阅读28次

Java

public class Solution {
    public int arrangeCoins(int n) {
        int result=0;
        int count=1;
        while(n>0)
        {
            if(n-count>=0)
            result++;
            n=n-count;
            count++;
        }
        return result;
    }
}

Java

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

相关文章

网友评论

      本文标题:441. Arranging Coins

      本文链接:https://www.haomeiwen.com/subject/zstsvttx.html