【leetcode】441. Arranging Coins
problem
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的更多相关文章
- 【LeetCode】441. Arranging Coins 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 模拟计算 二分查找 数学公式 日期 题目地址:htt ...
- 【LeetCode】979. Distribute Coins in Binary Tree 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 日期 题目地址:https://leetcod ...
- 【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 ...
- 【LeetCode】518. Coin Change 2 解题报告(Python)
[LeetCode]518. Coin Change 2 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目 ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- 【Leetcode】Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...
- 53. Maximum Subarray【leetcode】
53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...
- 27. Remove Element【leetcode】
27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...
- 【刷题】【LeetCode】007-整数反转-easy
[刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...
随机推荐
- Linux 进程后台运行
Linux 进程后台运行 1.进程在当前终端后台运行.(关闭终端后进程自动退出) sh test.sh & 注:运行进程后跟 “&” 2.进程长期后台运行不受终端关闭影响. nohup ...
- Shell cace条件语句
cace条件语句,取相对应的多个值,进行输出. 语句:case语句:case $n in 回车\ 值)回车\ 命令 :: 值)命令 esac case $1 in start) echo “启动” ...
- Reading Lines from File in C++
Reading Lines from File in C++ In C++, istringstream has been used to read lines from a file. code: ...
- Vim Tricks
Vim Tricks operations replace :$s/from/to/g 全文替换 :10,20s/from/to/g 从第10行开始,替换至第20行 :10,20s/from/to/g ...
- mysql密码的查看/修改
2.Mysql的Root密码忘记----查看或修改方法 2.1)启动命令行:windows微标键+R 2.2)在命令行输入taskkill /f /im mysqld.exe 回车,暂停Mysql服务 ...
- G711 G723 G729线路占多少带宽问题
G.711 G.711 也称为PCM(脉冲编码调制),是国际电信联盟订定出来的一套语音压缩标准,主要用于电话.它主要用脉冲编码调制对音频采样,采样率为8k每秒.它利用一个 64Kbps 未压缩 ...
- echarts的axisLabel的文字内容过长的解决办法
通过查找资料学习,我总结了四种解决的办法,不一定是最好的,但是希望能够帮助到需要的童鞋,同时如果大家有什么更好的方法欢迎指导. 方法一:这种方法就是将文本内容转换为字符串数组,然后再按需求换行,需要每 ...
- DAY11 函数(二)
一.函数的对象 1.1定义:函数名就是存放了函数的内存地址,存放了内存地址的变量都是对象,即 函数名 就是 函数对象 1.2函数对象的应用 1 可以直接被引用 fn = cp_fn def fn(): ...
- GO | KEGG的注释是怎么来的?
但凡是做过基因表达数据分析的(芯片.RNA-seq,scRNA-seq),肯定是跑过基因集功能注释和通路富集的,因为它是研究未知基因集的利器. 但跑过之后老板肯定会给反馈,通常得到的注释都是没有太多意 ...
- ionic UI Component Slides使用:手动滑动后自动滑动失效解决
在使用ionic的UI组件Slides时,发现手动滑动后,自动滑动失效 然后历经一点点的艰辛查找后找到方法,如下: 页面代码使用 <ion-slides pager loop="tru ...