441. Arranging Coins Easy
1/**
2 * [441] Arranging Coins
3 *
4 * 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.
5 * Given the integer n, return the number of complete rows of the staircase you will build.
6 *
7 * Example 1:
8 * <img alt="" src="https://assets.leetcode.com/uploads/2021/04/09/arrangecoins1-grid.jpg" style="width: 253px; height: 253px;" />
9 * Input: n = 5
10 * Output: 2
11 * Explanation: Because the 3^rd row is incomplete, we return 2.
12 *
13 * Example 2:
14 * <img alt="" src="https://assets.leetcode.com/uploads/2021/04/09/arrangecoins2-grid.jpg" style="width: 333px; height: 333px;" />
15 * Input: n = 8
16 * Output: 3
17 * Explanation: Because the 4^th row is incomplete, we return 3.
18 *
19 *
20 * Constraints:
21 *
22 * 1 <= n <= 2^31 - 1
23 *
24 */
25pub struct Solution {}
26
27// problem: https://leetcode.com/problems/arranging-coins/
28// discuss: https://leetcode.com/problems/arranging-coins/discuss/?currentPage=1&orderBy=most_votes&query=
29
30// submission codes start here
31
32impl Solution {
33 pub fn arrange_coins(n: i32) -> i32 {
34 0
35 }
36}
37
38// submission codes end
39
40#[cfg(test)]
41mod tests {
42 use super::*;
43
44 #[test]
45 fn test_441() {
46 }
47}
48
Back
© 2025 bowen.ge All Rights Reserved.