Skip to content

Commit 7317a86

Browse files
Add files via upload
1 parent f273425 commit 7317a86

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Arranging Coins/Arranging_Coins.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Runtime: 8 ms, faster than 56.82% of C++ online submissions for Arranging Coins.
2+
// Memory Usage: 8.3 MB, less than 71.43% of C++ online submissions for Arranging Coins.
3+
4+
class Solution
5+
{
6+
public:
7+
int arrangeCoins(int n)
8+
{
9+
if (n < 1)
10+
{
11+
return 0;
12+
}
13+
14+
long long limit = ceil(sqrt(2.0 * n));
15+
16+
for (long long i = limit; i >= 1; --i)
17+
{
18+
if ((1 + i) * i <= 2 * static_cast<long long>(n))
19+
{
20+
return i;
21+
}
22+
}
23+
24+
return 1;
25+
}
26+
};

0 commit comments

Comments
 (0)