441. Arranging Coins

Easy

You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins.

Given n, find the total number of full staircase rows that can be formed.

n is a non-negative integer and fits within the range of a 32-bit signed integer.

Example 1:

n = 5

The coins can form the following rows:
¤
¤ ¤
¤ ¤ Because the 3rd row is incomplete, we return 2.

Example 2:

n = 8

The coins can form the following rows:
¤
¤ ¤
¤ ¤ ¤
¤ ¤ Because the 4th row is incomplete, we return 3.
package leetcode.easy;

public class ArrangingCoins {
public int arrangeCoins(int n) {
int i = 0;
while (true) {
if (i <= n) {
n = n - i;
i++;
} else {
return i - 1;
}
}
} @org.junit.Test
public void test() {
System.out.println(arrangeCoins(5));
System.out.println(arrangeCoins(8));
}
}

LeetCode_441. Arranging Coins的更多相关文章

  1. 【leetcode】441. Arranging Coins

    problem 441. Arranging Coins solution1: class Solution { public: int arrangeCoins(int n) { ; ; while ...

  2. Leetcode之二分法专题-441. 排列硬币(Arranging Coins)

    Leetcode之二分法专题-441. 排列硬币(Arranging Coins) 你总共有 n 枚硬币,你需要将它们摆成一个阶梯形状,第 k 行就必须正好有 k 枚硬币. 给定一个数字 n,找出可形 ...

  3. [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 ...

  4. 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 ...

  5. [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 ...

  6. [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 ...

  7. C#LeetCode刷题之#441-排列硬币(Arranging Coins)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3995 访问. 你总共有 n 枚硬币,你需要将它们摆成一个阶梯形状 ...

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

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

  9. LeetCode "Arranging Coins"

    A simple math.. take care of data overflow though. class Solution { public: int arrangeCoins(int n) ...

随机推荐

  1. 用java刷剑指offer(数组中只出现一次的数字)

    题目描述 一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字. 牛客网链接 思路 链接:https://www.nowcoder.com/questionTer ...

  2. ServicePoint 类

    地址:https://docs.microsoft.com/zh-cn/dotnet/api/system.net.servicepoint?view=netframework-4.7.2 提供 HT ...

  3. C++学习(1)—— 初识C++

    1. 变量 作用:给一段指定的内存空间起名,方便操作这段内存空间 语法:数据类型 变量名称=变量初始值​ #include<iostream> using namespace std; i ...

  4. 矩阵指数 Matrix Exponentials

    转自:https://zh.wikipedia.org/wiki/%E7%9F%A9%E9%98%B5%E6%8C%87%E6%95%B0 其中,X. X2.X3…….Xk 都是n阶矩阵,显然 exp ...

  5. 矩阵迹tr(AA*)的计算公式证明

    与tr(AB)=tr(BA)的证明思路相同,均使用矩阵的元素表示形式进行证明.

  6. python怎么连接MongoDB数据库

    Python 要连接 MongoDB 需要 MongoDB 驱动,这里我们使用 PyMongo 驱动来连接. pip 安装: pip3 install pymongo 引入库: import pymo ...

  7. linux的后台运行相关命令

    screen -S name 创建一个名为name的后台,或者说bash面板,在这上面运行的任务不会因为连接断开而退出,且保留bash上的信息 screen -ls 列出所有的screen scree ...

  8. 大数据之路week07--day07 (修改mysql默认编码)

    在Sqoop导入或者导出,我们在查看mysql的时候会出现中文乱码大部分乱码会是?这样的问号,那么该怎么处理呢? 1.打开my.cnf文件  vim /etc/my.cnf 2.找到对应需要修改的地方 ...

  9. DT资讯文章生成静态出现MySQL Error解决办法

    今天有个朋友的DT系统生成静态出现 MySQL Query:SELECT * FROM [pre]article_21 WHERE status=3 and itemid<>516548 ...

  10. Codeforces Round #605 (Div. 3) A. Three Friends(贪心)

    链接: https://codeforces.com/contest/1272/problem/A 题意: outputstandard output Three friends are going ...