[LeetCode] 441. Arranging Coins_Easy tag: Math
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的更多相关文章
- [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. ...
- [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 ...
- 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 ...
- [LeetCode] 504. Base 7_Easy tag: Math
Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202&q ...
- [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 ...
- [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 ...
- 【leetcode】441. Arranging Coins
problem 441. Arranging Coins solution1: class Solution { public: int arrangeCoins(int n) { ; ; while ...
- Leetcode Tags(6)Math
一.204. Count Primes Count the number of prime numbers less than a non-negative number, n. Input: 10 ...
- [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 ...
随机推荐
- Intersection Observer API 可以让你知道被观察元素何时进入或退出浏览器的视口
google 文档 https://developers.google.cn/web/updates/2016/04/intersectionobserver MDN 文档 https://devel ...
- eclipse下配置Spring环境
工具: jdk1.8 win10 spring5.0 1.准备工作:下载Spring开发应用的插件,api 1.spring插件包:springsource-tool-suite-3.9.4.RELE ...
- ARM Linux Oops使用小结(转)
出现Oops消息的大部分错误时因为对NULL指针取值或者因为用了其他不正确的指针值. Oops如何产生的解释如下: 由于处理器使用的地址几乎都是虚拟地址,这些地址通过一个被称为“页表”的结构被 ...
- PAT甲级1052 Linked List Sorting
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805425780670464 题意: 给定一些内存中的节点的地址,值 ...
- mysql日期格式转换,如何保持原日期?CONVERT/Substring 函数截取。replace替换
http://www.cnblogs.com/stevenjson/p/3729577.html CONVERT(varchar(100), getdate(), 112)这种, 问题就出在getda ...
- [No000010F]Git8/9-使用GitHub
我们一直用GitHub作为免费的远程仓库,如果是个人的开源项目,放到GitHub上是完全没有问题的.其实GitHub还是一个开源协作社区,通过GitHub,既可以让别人参与你的开源项目,也可以参与别人 ...
- MyBatis中choose when正确写法
<choose> <when test="scoreRange!=null and scoreRange eq 1"> AND sc.score <! ...
- Mean reversion (finance) 均值回归
Mean reversion (finance) 均值回归
- inotifywait实现目录监控--http://man.linuxde.net/inotifywait
sudo apt install inotify-tools while inotifywait -q -r -e create,delete,modify,move,attrib --exclude ...
- [centos][ntp][administrator] chrony ntp
以下内容,适用于 CentOS 7 (systemd 体系) 一. 首先,确认你是否启用了 ntp 服务: [root@nlb2-liantiao ~]# timedatectl Local time ...