-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path441.arranging-coins.cpp
More file actions
58 lines (57 loc) · 1.03 KB
/
441.arranging-coins.cpp
File metadata and controls
58 lines (57 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* @lc app=leetcode id=441 lang=cpp
*
* [441] Arranging Coins
*
* https://leetcode.com/problems/arranging-coins/description/
*
* algorithms
* Easy (45.72%)
* Likes: 2471
* Dislikes: 1073
* Total Accepted: 296.5K
* Total Submissions: 648.5K
* Testcase Example: '5'
*
* You have n coins and you want to build a staircase with these coins. The
* staircase consists of k rows where the i^th row has exactly i coins. The
* last row of the staircase may be incomplete.
*
* Given the integer n, return the number of complete rows of the staircase you
* will build.
*
*
* Example 1:
*
*
* Input: n = 5
* Output: 2
* Explanation: Because the 3^rd row is incomplete, we return 2.
*
*
* Example 2:
*
*
* Input: n = 8
* Output: 3
* Explanation: Because the 4^th row is incomplete, we return 3.
*
*
*
* Constraints:
*
*
* 1 <= n <= 2^31 - 1
*
*
*/
// @lc code=start
class Solution
{
public:
unsigned short int arrangeCoins(unsigned int n)
{
return sqrt(0.25 + 2 * n) - 0.5;
}
};
// @lc code=end