We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c897072 commit 0646b1bCopy full SHA for 0646b1b
Day-1_Arranging_Coins.py
@@ -0,0 +1,38 @@
1
+'''
2
+ 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.
3
+
4
+Given n, find the total number of full staircase rows that can be formed.
5
6
+n is a non-negative integer and fits within the range of a 32-bit signed integer.
7
8
+Example 1:
9
10
+n = 5
11
12
+The coins can form the following rows:
13
+¤
14
+¤ ¤
15
16
17
+Because the 3rd row is incomplete, we return 2.
18
+Example 2:
19
20
+n = 8
21
22
23
24
25
+¤ ¤ ¤
26
27
28
+Because the 4th row is incomplete, we return 3.
29
30
31
32
33
34
35
36
+class Solution:
37
+ def arrangeCoins(self, n: int) -> int:
38
+ return int((-1 + math.sqrt(1 + 8 * n)) / 2)
0 commit comments