leetcode441
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 - );
}
}
https://leetcode.com/problems/arranging-coins/#/description
leetcode441的更多相关文章
- leetcode441(巧妙利用取整和解方程)
You have a total of n coins that you want to form in a staircase shape, where every k-th row must ha ...
- [Swift]LeetCode441. 排列硬币 | Arranging Coins
You have a total of n coins that you want to form in a staircase shape, where every k-th row must ha ...
随机推荐
- sql语句in
在今天之前sql一直用in语句,知道今天遇到一张数据量很大的表查了三分钟才查出来,这才意识到数据库优化有多重要.作为一名开发人员,首先从优化sql语句开始. 之前用in写sql是这样的 select ...
- III USP Freshmen ContestH. MaratonIME gets candies
这题挺有意思的,刚开始不会这交互题,模仿着做了一题就会了,蛮简单 的 这题我用2分,结果wa了,想了一下发现,1到1e9二分50次完全不够用啊,那就转换一下思维,先求出在10^n~10^(n+1)的n ...
- 微信小程序封装storage(含错误处理)
这次给你们安利的是微信小程序封装storage,先说下微信官方的 wx.getStorage({ key:"", success: function (res) { }, fail ...
- dbms_job.submit方式创建job,太老了
--方法一declarejobno number; begin dbms_job.submit(jobno, 'xxxx;', xxxx, 'xxxx'); commit ...
- 【Python】重载模块
命令窗口中调试代码,往往需要重载模块已进行最新的代码调试. 主要有两种方式: 1. Python shell 窗口 reload(module) 2. ipython 窗口 %load_ext aut ...
- 16Aspx源码论坛
16Aspx源码论坛: http://bbs.16aspx.com/index.aspx
- elasticsearch 自定义similarity 插件开发
转自:http://www.chepoo.com/elasticsearch-similarity-custom-plug-in-development.html 在搜索开发中,我们要修改打分机制,就 ...
- iptables Configuration
iptables usage: Add Rules: iptables -I INPUT -p tcp --dport -j ACCEPT iptables -I INPUT -p tcp --dpo ...
- 抽象工厂 C++实现
抽象工厂(Abstract Factory) 抽象工厂是为了提供一系列相关或相互依赖对象的接口.对象创建型模式的一种. 客户Client 抽象工厂接口AbstractFactory 抽象工厂的实现类C ...
- c++的c风格字符串函数的实现
要注意使用断言判断传入的字符串非空. #include <cassert> //求字符串长度 size_t StrLen(const char *str) { assert(str != ...