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 ...
随机推荐
- Eclipse 常用快捷键和使用技巧
1.查看快捷键定义的地方 Window->Preferences->General->Keys. 2.更改启动页 在AndroidManifest.xml第一个activity标签项 ...
- Tensorflow学习笔记二
现在来开始安装Tensorflow吧 Tensorflow有两种模式, 一种GPU支持, 另外一种仅CPU支持 虚拟机仅有CPU支持, 那就第一种模式吧 有4种途径去安装 virtualenv &qu ...
- BZOJ1074 [SCOI2007]折纸origami
我们先看每个点可能从哪些点折过来的,2^10枚举对角线是否用到. 然后再模拟折法,查看每个点是否满足要求. 恩,计算几何比较恶心,还好前几天刚写过一道更恶心的计算几何,点类直接拷过来2333. /** ...
- HDU 4686 Arc of Dream 矩阵快速幂,线性同余 难度:1
http://acm.hdu.edu.cn/showproblem.php?pid=4686 当看到n为小于64位整数的数字时,就应该有个感觉,acm范畴内这应该是道矩阵快速幂 Ai,Bi的递推式题目 ...
- jQuery的无new创建方法
一般我们去写一个框架,会采用什么样的设计呢?比如设计一个jQuery框架,一般我们会创建一个函数对象 function jQuery(params){ //构造函数 }jQuery.prototype ...
- Alpha阶段第1周 Scrum立会报告+燃尽图 07
作业要求与https://edu.cnblogs.com/campus/nenu/2018fall/homework/2246相同 一.小组介绍 组长:刘莹莹 组员:朱珅莹 孙韦男 祝玮琦 王玉潘 周 ...
- memcache+tomcat7.0.37+nginx实现session共享
一.session工作原理 由于http是无状态的协议,当我们访问了页面A,然后访问页面B,http无法确定这2个页面的访问是来自同一个人.因此,我们要用cookie或session来跟踪用户,根据授 ...
- Ubuntu系统配置apt-get软件更新源
从别人那摘录的Ubuntu源,测的很好用 # 电子科技大学 (教育网) deb http://ubuntu.uestc.edu.cn/ubuntu/ oneiric main restricted u ...
- ZetCode PyQt4 tutorial basic painting
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...
- pidgin-lwqq
今天第一次用pidgin登上了qq,好神奇. 从网上看到的,说是pidgin发布了支持webqq协议的lwqq,按照解释之后安装了. 感觉好神奇啊. 一个绿色的小企鹅^^ 今天有看到了一个大牛,我觉得 ...