leetcode441
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的更多相关文章
- leetcode441(巧妙利用取整和解方程)
You have a total of n coins that you want to form in a staircase shape, where every k-th row must ha ...
- [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 ...
随机推荐
- VM虚拟机安装的XP如何全屏
首先安装install VMwear Tools..,如图:
- HDU 1241 Oil Deposits bfs 难度:0
http://acm.hdu.edu.cn/showproblem.php?pid=1241 对每个还未访问的点bfs,到达的点都标为一块,最后统计有多少块即可 #include <cstdio ...
- SQL 字符串拆分
字符串拆分: ALTER FUNCTION [dbo].[f_Split](@sText nvarchar(max),@split NVARCHAR(20)) RETURNS @t TABLE (id ...
- Class 'SoapClient' not found 解决方法
Class 'SoapClient' not found ? 在百度上搜了解决办法,可是收效不佳,只知道好像要添加soap扩展模块,但怎么添加却没有说.于是,我上了google.果然,查看一些英文资料 ...
- Scrum立会报告+燃尽图 06
作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2289] 版本控制:https://git.coding.net/liuyy08 ...
- python 读写三菱PLC数据,使用以太网读写Q系列,L系列,Fx系列的PLC数据
本文将使用一个gitHub开源的组件技术来读写三菱的plc数据,使用的是基于以太网的TCP/IP实现,不需要额外的组件,读取操作只要放到后台线程就不会卡死线程,本组件支持超级方便的高性能读写操作 gi ...
- 《FDTD electromagnetic field using MATLAB》读书笔记之一阶、二阶偏导数差商近似
- 【Python】matplotlib 双y轴绘制及合并图例
1.双y轴绘制 关键函数:twinx() 问题在于此时图例会有两个. # -*- coding: utf-8 -*- import numpy as np import matplotlib.pypl ...
- 安装node
vuejs:通过npm安装vue框架(印象深刻的问题出在了npm上) 以下所有事我自己在windows系统下遇到的问题 一.安装nodejs node下载地址https://nodejs.org/en ...
- nginx 配置实现逻辑预算
nginx 的配置 不支持逻辑与和逻辑非运算,也不支持if 嵌套,只能用其他方式实现 set $flag 0; if ($host != name) { set $flag "${flag} ...