Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fd295a3

Browse files
committedFeb 16, 2025
Add solution #441
1 parent 1545a27 commit fd295a3

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@
266266
434|[Number of Segments in a String](./0434-number-of-segments-in-a-string.js)|Easy|
267267
435|[Non-overlapping Intervals](./0435-non-overlapping-intervals.js)|Medium|
268268
437|[Path Sum III](./0437-path-sum-iii.js)|Medium|
269+
441|[Arranging Coins](./0441-arranging-coins.js)|Easy|
269270
442|[Find All Duplicates in an Array](./0442-find-all-duplicates-in-an-array.js)|Medium|
270271
443|[String Compression](./0443-string-compression.js)|Medium|
271272
448|[Find All Numbers Disappeared in an Array](./0448-find-all-numbers-disappeared-in-an-array.js)|Easy|

‎solutions/0441-arranging-coins.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* 441. Arranging Coins
3+
* https://leetcode.com/problems/arranging-coins/
4+
* Difficulty: Easy
5+
*
6+
* You have n coins and you want to build a staircase with these coins. The staircase consists
7+
* of k rows where the ith row has exactly i coins. The last row of the staircase may be incomplete.
8+
*
9+
* Given the integer n, return the number of complete rows of the staircase you will build.
10+
*/
11+
12+
/**
13+
* @param {number} n
14+
* @return {number}
15+
*/
16+
var arrangeCoins = function(n) {
17+
let count = 0;
18+
for (; count <= n; count++) {
19+
n -= count;
20+
}
21+
return count - 1;
22+
};

0 commit comments

Comments
 (0)
Please sign in to comment.