leetcode441

Posted AsenYang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode441相关的知识,希望对你有一定的参考价值。

public class Solution {
    public int ArrangeCoins(int n) {
        //convert int to long to prevent integer overflow
            long nLong = (long)n;
            long st = 0;
            long ed = nLong;
            long mid = 0;
            while (st <= ed)
            {
                mid = st + (ed - st) / 2;

                if (mid * (mid + 1) <= 2 * nLong)
                {
                    st = mid + 1;
                }
                else
                {
                    ed = mid - 1;
                }
            }
            return (int)(st - 1);
    }
}

https://leetcode.com/problems/arranging-coins/#/description

以上是关于leetcode441的主要内容,如果未能解决你的问题,请参考以下文章

leetcode-441. Arranging Coins

leetcode441

LeetCode 441. Arranging Coins

LeetCode 441. Arranging Coins

LeetCode 441. Arranging Coins

LeetCode 441 Arranging Coins