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的更多相关文章

  1. leetcode441(巧妙利用取整和解方程)

    You have a total of n coins that you want to form in a staircase shape, where every k-th row must ha ...

  2. [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 ...

随机推荐

  1. Android Studio 中实现高德定位并获取相应信息

    Android开发项目时常常会遇到定位这个功能,所以写了这篇博客,今天主要讲的高德地图的定位并获取相应信息. 首先导入高德的jar包 选中jar包右键点击  Add As Library, 在buil ...

  2. MySql中Blob与Text的区别

    BLOB是一个二进制大对象,可以容纳可变数量的数据.有4种BLOB类型:TINYBLOB.BLOB.MEDIUMBLOB和LONGBLOB.它们只是可容纳值的最大长度不同. 有4种TEXT类型:TIN ...

  3. MongoDB学习(五)使用Java驱动程序3.3操作MongoDB快速入门

    [引言] 毕竟现在MongoDB还是出于成长阶段,所以现在网上相关的资料很少,而且大部分还都是针对于MongoDB的老版本的.再加上MongoDB的频繁升级.重大更新等等,导致菜鸟学习的难度增大. 好 ...

  4. Javascript几种创建对象的方法

    1.工厂方法 demo.js 1 2 3 4 5 6 7 8 9 10 11 function createPerson(name, age) { var person = new Object(); ...

  5. 在jenkins和sonar中集成jacoco(三)--使用jacoco收集集成测试的覆盖率

    我们系统使用weblogic做服务器,集成测试框架使用的是junit+selenium. 首先,要把jacoco的jacocoagent.jar包放到部署应用的服务器上,接着在系统服务的JAVA_OP ...

  6. TF随笔-13

    import tensorflow as tf a=tf.constant(5) b=tf.constant(3) res1=tf.divide(a,b) res2=tf.div(a,b) with ...

  7. HDU 4764:Stone(巴什博弈)

    Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  8. Anatoly and Cockroaches

    Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also li ...

  9. 关于const 和指针

    这个很久之前就很困扰的问题,现在再理一下: 1,指向const对象的指针 >C++强制要求指向const对象的指针也必须具有const特性!!!也就是不能把一个const对象的地址赋给一个非co ...

  10. graphql-yoga 项目简单使用&&集成docker

      graphql-yoga 是一个实现了grahql的框架,使用简单,便捷 具体源码参考github https://github.com/rongfengliang/graphql-yoga-do ...