problem

441. Arranging Coins

solution1:

class Solution {
public:
int arrangeCoins(int n) {
long sum = ;
int curLevel = ;
while(sum<=n)
{
curLevel += ;
sum += curLevel;
}
return (curLevel-);
}
};

solution2:

class Solution {
public:
int arrangeCoins(int n) {
return (int)((sqrt(*(long)n+)-)*0.5);//数学求和公式求解x,注意参数类型是否越界.
}
};

solution3:

class Solution {
public:
int arrangeCoins(int n) {
if(n<=) return n;//err.
int left = , right = n, mid = ;
while(left<right)
{
mid = left + (right-left)*0.5;
if((long)mid*(mid+)*0.5 <= n) left = mid+;
else right = mid;
}
return left-;//err.
}
};

参考

1. Leetcode_441. Arranging Coins;

【leetcode】441. Arranging Coins的更多相关文章

  1. 【LeetCode】441. Arranging Coins 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 模拟计算 二分查找 数学公式 日期 题目地址:htt ...

  2. 【LeetCode】979. Distribute Coins in Binary Tree 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 日期 题目地址:https://leetcod ...

  3. 【leetcode】979. Distribute Coins in Binary Tree

    题目如下: Given the root of a binary tree with N nodes, each node in the tree has node.val coins, and th ...

  4. 【LeetCode】518. Coin Change 2 解题报告(Python)

    [LeetCode]518. Coin Change 2 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目 ...

  5. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

  6. 【Leetcode】Pascal&#39;s Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...

  7. 53. Maximum Subarray【leetcode】

    53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...

  8. 27. Remove Element【leetcode】

    27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...

  9. 【刷题】【LeetCode】007-整数反转-easy

    [刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...

随机推荐

  1. JavaScript Dom0 Dom1

    行为 样式 结构相分离的页面 JS        CSS       HTML DOM 0写法 <!DOCTYPE html> <html lang="en"&g ...

  2. 学习了一天的python,终于可以爬爬了-_-

    恒久恒久以前在语言大陆就听过一种叫,人生苦短,我用python的至理名言.陆陆续续在课下和业余生活中学习的一点python,知道基本的语法和规则,不过py的库实在是太多了,而且许多概念也没有深入的学习 ...

  3. jquery easyui的应用-2

    有两个版本: freeware edition, commercial edition easyui的 datagrid 实际上是一个table, 其数据来源 通过 url属性来从后台的php页面 获 ...

  4. 马上AI全球挑战者大赛-违约用户风险预测

    方案概述 近年来,互联网金融已经是当今社会上的一个金融发展趋势.在金融领域,无论是投资理财还是借贷放款,风险控制永远是业务的核心基础.对于消费金融来说,其主要服务对象的特点是:额度小.人群大.周期短, ...

  5. 【Python】【装饰器】

    Python中的装饰器是你进入Python大门的一道坎,不管你跨不跨过去它都在那里. 为什么需要装饰器 我们假设你的程序实现了say_hello()和say_goodbye()两个函数. def sa ...

  6. python 警惕 IEEE 754标准

    双精度浮点数格式,即IEEE 754标准 >>> 0.1+0.2 0.30000000000000004 >>> (0.1+0.2)==0.3 False > ...

  7. k-mean 拐点

    n = 100g = 6 set.seed(g)d <- data.frame(x = unlist(lapply(1:g, function(i) rnorm(n/g, runif(1)*i^ ...

  8. python中isdigit

    line = "12r45ofjo13jr3 3j"print line[0:3].isdigit()返回:false line = "12345ofjo13jr3 3j ...

  9. TCP建立连接为什么是三次握手,为什么不是两次或四次?

    什么是三次握手 学过网络编程的人,应该都知道TCP建立连接的三次握手,下面简单描述一下这个过程. 如图所示 第一次握手:客户端发送TCP包,置SYN标志位为1,将初始序号X,保存在包头的序列号(Seq ...

  10. SAP WDA 自建Portal

    1.新建Package:ZWDA. 2.新建Portal用户表:ZPORTAL_USER 上图中是基于CRM的BP来做的用户表,如果针对其他系统可以使用组织架构里的角色用户... 3.新建用户视图配置 ...