public class Solution {
public int ArrangeCoins(int n) {
//convert int to long to prevent integer overflow
long nLong = (long)n;
long st = ;
long ed = nLong;
long mid = ;
while (st <= ed)
{
mid = st + (ed - st) / ; if (mid * (mid + ) <= * nLong)
{
st = mid + ;
}
else
{
ed = mid - ;
}
}
return (int)(st - );
}
}
相关文章
- 01-12leetcode441
- 01-12leetcode441(巧妙利用取整和解方程)