[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 ...
随机推荐
- 火狐浏览器报错“support.mozilla.org
火狐浏览器有时候再打开新网页会报此错“support.mozilla.org 有时候火狐浏览器会出现如下状况 解决方法 在地址栏键入”about:config” 点击“我了解此风险” 在下方任意位置右 ...
- Selenium模拟浏览器抓取淘宝美食信息
前言: 无意中在网上发现了静觅大神(崔老师),又无意中发现自己硬盘里有静觅大神录制的视频,于是乎看了其中一个,可以说是非常牛逼了,让我这个用urllib,requests用了那么久的小白,体会到sel ...
- zabbix监控告警Received empty response from Zabbix Agent Assuming that agent dropped connection
zabbix监控告警Received empty response from Zabbix Agent Assuming that agent dropped connection错误 查看zabbi ...
- DB2 的代理 (agent)
DB2 的代理 (agent) 是位于 DB2 服务器中的服务于应用程序请求的一些进程或线程.当有外部应用程序连接至 DB2 实例提出访问请求时,DB2 的代理就会被激活去应答这些请求.一般 DB2 ...
- [No0000F8]override和new的区别
override 1. override是派生类用来重写(或覆盖)基类中方法的: 2. override不能重写非虚方法和静态方法: 3. override只能重写用virtual.abstract. ...
- 基于Docker搭建MySQL主从复制
摘要: 本篇博文相对简单,因为是初次使用Docker,MySQL的主从复制之前也在Centos环境下搭建过,但是也忘的也差不多了,因此本次尝试在Docker中搭建. 本篇博文相对简单,因为是初次使用D ...
- 自动化运维工具-pdsh工具安装配置及简单使用讲解
1.先决条件: 安装pssh工具的主机针对远程主机需要配置免秘钥认证: ssh-keygen -t rsa ssh-copy-id [remotehost] 2.下载pssh工具安装介质: https ...
- /etc/apt/sources.list" E212: Can't open file for writing解决方案
:w !sudo tee % > /dev/null 解决.
- Uniform Resource Name Server
HTTP The Definitive Guide 按址标识 identify by address 按名标识 identify by name Domain Name Server Uniform ...
- 添加图片后xcode报错:resource fork, Finder information, or similar detritus not allowed
/Users/songximing/Library/Developer/Xcode/DerivedData/Children-cvqgzlzddltkfndhdmzedxbnoxwx/Build/Pr ...