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. 利用 x(x+1)/2 <= n 求得x = (sqrt(8*n+1) -1)/2 Code O(1)
class Solution:
def arrageCoins(self, n):
return (int(math.sqrt(8*n +1) -1)//2)

[LeetCode] 441. Arranging Coins_Easy tag: Math的更多相关文章

  1. [LeetCode] 258. Add Digits_Easy tag: Math

    Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...

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

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

  4. [LeetCode] 504. Base 7_Easy tag: Math

    Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202&q ...

  5. [LeetCode] 292. Nim Game_Easy tag: Math

    You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...

  6. [LeetCode] 458. Poor Pigs_Easy tag: Math

    There are 1000 buckets, one and only one of them contains poison, the rest are filled with water. Th ...

  7. 【leetcode】441. Arranging Coins

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

  8. Leetcode Tags(6)Math

    一.204. Count Primes Count the number of prime numbers less than a non-negative number, n. Input: 10 ...

  9. [LeetCode] 130. Surrounded Regions_Medium tag: DFS/BFS

    Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'. A reg ...

随机推荐

  1. Convert PLY to VTK Using PCL 1.6.0 or PCL 1.8.0 使用PCL库将PLY格式转为VTK格式

    PLY格式是比较流行的保存点云Point Cloud的格式,可以用MeshLab等软件打开,而VTK是医学图像处理中比较常用的格式,可以使用VTK库和ITK库进行更加复杂的运算处理.我们可以使用Par ...

  2. ERP项目实施记录04

    周二做了计划部门的需求调查,提到现有计划(一天计划)的准确率仅有60~70%,每天下来都有30%~40%不能达成. 计划部门提出的需求更多是基于Excel操作思路,要求未来的系统要有更多的" ...

  3. NOIP2018旅游记

    2018.12.4更新: GD分数线出了,1=分数线310,1=了 好歹能和cyp交代了吧) 2018.11.28更新: 不好意思,太懒了,加上我也不记得后来发生什么了,总之就这样太监了. noip2 ...

  4. ubuntu下c/c++/python/go编译运行

    C语言: .c文件 编译器gcc//my_code下hello.c文件 $sudo apt install gcc $gcc hello.c -o hello $./hello C++: .cpp文件 ...

  5. day0318装饰器和内置函数

    一.装饰器 1.装饰器: 解释:装饰器的本事就是一个函数,不改动主代码的情况下,增加新功能.返回值也是一个函数对象. 2.装饰器工作过程 import time def func(): print(' ...

  6. CALayer的子类之CAShapeLayer

    一,CAShapeLayer介绍 * CAShapeLayer继承自CALayer,属于QuartzCore框架,可使用CALayer的所有属性.   CAShapeLayer是在坐标系内绘制贝塞尔曲 ...

  7. centos 安装ss

    yum install python-setuptools && easy_install pip pip install shadowsocks vi /etc/shadowsock ...

  8. tensorflow入门笔记(四) tf.summary 模块

    模块内的函数: tf.summary.audio(name, tensor, sample_rate, max_outputs=3, collections=None, family=None) 输出 ...

  9. AT2134 Zigzag MST 最小生成树

    正解:最小生成树 解题报告: 先放下传送门QAQ 然后这题,首先可以发现这神奇的连边方式真是令人头大,,,显然要考虑转化掉QAQ 大概看一下可以发现点对的规律是,左边++,交换位置,再仔细想下,就每个 ...

  10. 【Python全栈-HTML】HTML入门

    HTML入门介绍 参考: https://www.bilibili.com/video/av21663728/?p=339 http://www.cnblogs.com/yuanchenqi/arti ...