arranging-coins
https://leetcode.com/problems/arranging-coins/
public class Solution {
    public int arrangeCoins(int n) {
        // n >= x*(x+1)/2; 2n >= x^2 + x; 8n+1 >= 4x^2 + 4x + 1 = (2x+1)^2
        // (8n+1)^(1/2) = 2x+1; x = ((8n+1)^(1/2)-1)/2;
        // 注意下面的n要转成long,不然可能溢出
        return (int)(Math.sqrt(8*(long)n+1)-1)/2;
    }
}
arranging-coins的更多相关文章
- 【leetcode】441. Arranging Coins
		problem 441. Arranging Coins solution1: class Solution { public: int arrangeCoins(int n) { ; ; while ... 
- Leetcode之二分法专题-441. 排列硬币(Arranging Coins)
		Leetcode之二分法专题-441. 排列硬币(Arranging Coins) 你总共有 n 枚硬币,你需要将它们摆成一个阶梯形状,第 k 行就必须正好有 k 枚硬币. 给定一个数字 n,找出可形 ... 
- LeetCode_441. Arranging Coins
		441. Arranging Coins Easy You have a total of n coins that you want to form in a staircase shape, wh ... 
- [LeetCode] 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 ... 
- LeetCode 441 Arranging Coins
		Problem: You have a total of n coins that you want to form in a staircase shape, where every k-th ro ... 
- [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 ... 
- [LeetCode] 441. 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 ... 
- C#LeetCode刷题之#441-排列硬币(Arranging Coins)
		问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3995 访问. 你总共有 n 枚硬币,你需要将它们摆成一个阶梯形状 ... 
- 【LeetCode】441. Arranging Coins 解题报告(Python)
		作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 模拟计算 二分查找 数学公式 日期 题目地址:htt ... 
- LeetCode "Arranging Coins"
		A simple math.. take care of data overflow though. class Solution { public: int arrangeCoins(int n) ... 
随机推荐
- java web项目,java类中获得WEB-INF路径
			private static String getWebInfPath() { URL url = 当前类.class.getProtectionDomain().getCodeSource().ge ... 
- JavaScript原生折叠扩展收缩菜单带缓冲动画
			JavaScript原生折叠扩展收缩菜单带缓冲动画 @落雨 <div id="div_two" style="display: none;"> &l ... 
- XSS的原理分析与解剖(一)
			0×01 前言: <xss攻击手法>一开始在互联网上资料并不多(都是现成的代码,没有从基础的开始),直到刺的<白帽子讲WEB安全>和cn4rry的<XSS跨站脚本攻击剖析 ... 
- css之margin && padding讲解
			margin && padding盒子模型: margin是模块与模块的空隙,padding是内容与边框的空隙 注: 1.margin:边缘.空白 2.padding:填充 margi ... 
- Unity3D 将 Unity 嵌入WPF中的一些研究笔记
			一. 在 WPF 中使用 WebBrowser,直接打开 WebPlayer.html 以这种方式有一个问题是. 无法在 WebBrowser 的上面 放置其它的控件, 在运行时,都不会显示 . 以 ... 
- PHP一些函数
			函数不定参数: func_num_args // 获得参数个数 func_get_args // 获得参数数组 call_user_func('function_name', $parameter) ... 
- jstl 的应用 java
			JSTL :JSP Standard Tag Library,JSP标准标签库 1.导入包 jstl.jar standard.jar 2.页面中添加标识 <%@taglib uri=" ... 
- (8)nehe教程2-多边形
			参考自: http://www.yakergong.net/nehe/ 你的第一个多边形: 在第一个教程的基础上,我们添加了一个三角形和一个四边形.也许你认为这很简单,但你已经迈出了一大步,要知道任何 ... 
- UVA 11806 Cheerleaders   dp+容斥
			In most professional sporting events, cheerleaders play a major role in entertaining the spectators. ... 
- Android 核心分析 之八Android 启动过程详解
			Android 启动过程详解 Android从Linux系统启动有4个步骤: (1) init进程启动 (2) Native服务启动 (3) System Server,Android服务启动 (4) ... 
