Leetcode 441. Arranging Coins
題目的意思是一共有n個硬幣,需要將它們擺成樓梯的形狀,第k節樓梯有k枚硬幣。求一共可以擺滿多少層樓梯。
方法1:擺滿k層樓梯,一共需要(1+k)*k/2枚硬幣。令(1+k)*k/2=n,求出的k取整就是所求。不過要注意8*n有可能越界,所以要用8.0*n,這樣8.0是double,8.0*n也就變成了double.
class Solution {
public:
int arrangeCoins(int n) {
return (sqrt(1+8.0*n)-1)/2;
}
};
相關文章
- 【Leetcode】441. Arranging CoinsLeetCode
- Leetcode 解析 (441. Arranging Coins)LeetCode
- LeetCode C++ 441. Arranging Coins【Math/Binary Search】簡單LeetCodeC++
- In this new Buy fifa coins? area
- 【Arranging an Appointment】Unit1 Part3APP
- EverQuest Buy fifa coins site launched
- GameSpot How is Buy fifa coins? developmentGAMdev
- The Buy fifa coins Xbox is saidAI
- POJ-2000 Gold CoinsGo
- [Atcoder DP I]Coins 題解
- Sony Pictures Buy fifa coins ? Digital EntertainmentGitAI
- but youre quickly Fifa 14 ultimate team coins bombardedUI
- HDOJ-1398 Square Coins(母函式)函式
- 「SWTR-4」Collecting Coins 題解
- Where do you go Fifa 14 ultimate team coins afterGo
- Nintendo itself Fifa 14 ultimate team coins isnt bringing
- HDU3519Lucky Coins Sequence(DP+矩陣加速)矩陣
- 杭電ACM hdu 1398 Square Coins 解題報告(母函式)ACM函式
- YT15-HDU-Harry's parents had left him a lot of gold coinsGo
- 【LeetCode】如何學習LeetCode?LeetCode
- LeetcodeLeetCode
- LeetCode in actionLeetCode
- Leetcode AnagramsLeetCode
- Leetcode SortListLeetCode
- Leetcode ReorderListLeetCode
- leetcode SubsetsLeetCode
- Leetcode PermutationsLeetCode
- HDU 母函式簡單題 - 找單詞/Ignatius and the Princess III/Square Coins/Holding Bin-Laden Captive!函式APT
- [LeetCode刷題筆記] 關於LeetCode的前言LeetCode筆記
- 我的 LeetCodeLeetCode
- Leetcode學習LeetCode
- LeetCode 53 JSLeetCodeJS
- LeetCode 50 JSLeetCodeJS
- LeetCode 克隆圖LeetCode
- Leetcode Perfect SquaresLeetCode
- Leetcode Sort ColorsLeetCode
- Leetcode Sort ArrayLeetCode
- 【LeetCode】Jewels and StonesLeetCode