【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-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...
随机推荐
- Docker Kubernetes 查询字段说明
Docker Kubernetes 查询字段说明 # 打印受支持的API版本 kubectl api-versions # 扩展 apiextensions.k8s.io/v1beta1 # 注册 ...
- opencv3.0之后IPLimage转换成MAT的问题
转自http://www.cnblogs.com/edver/p/5187190.html IplImage * ipl = ...; cv::Mat m = cv::cvarrToMat(ipl); ...
- pytorch中的若干问题
下载pytorch: 度盘 https://pan.baidu.com/s/1dF6ayLr?errno=0&errmsg=Auth%20Login%20Sucess&&bdu ...
- postman+linux+pistache的http通信过程
一.pistache配置 1.安装cmake[https://www.cnblogs.com/judes/p/10327638.html] 2.下载pistache[git:https://githu ...
- Bytom Java版本离线签名
比原项目仓库: Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom tx_s ...
- 在 mac iTerm2 中使用 cmd 终端
在 mac iTerm2 中使用 cmd 终端 主要是因为要在 window 中做一些命令行上的工作, 但又不想切换到整个 window 系统里面去. 在程序和功能中开启 telnet 在服务中启用 ...
- C# 实现邮件收取发送功能
.Net调用QQ邮箱发送邮件 话说网上发送邮件的代码很多,但是我由于不细心,导致拿别人的代码发送邮件老是失败,今天就说说几个要注意的地方吧!!! ? 1 2 3 4 5 6 7 8 9 10 11 ...
- Lab 7-3
For this lab, we obtained the malicious executable, Lab07-03.exe, and DLL, Lab07-03.dll, prior to ex ...
- 文件下载 路径中有中文 报错 提示 文件找不到 java.io.FileNotFoundException: http://192.168.1.141:8096/resources/card/comcard/????????/????????.png
此问题主要是中文编码格式不对导致的,将路径中的中文部分设置下编码就可以啦 例如: String url = "http://192.168.1.141:8096/resources/car ...
- android ------- 开发者的 RxJava 详解
在正文开始之前的最后,放上 GitHub 链接和引入依赖的 gradle 代码: Github: https://github.com/ReactiveX/RxJava https://github. ...