441. Arranging Coins - Easy
前往題目
想法
- 循環扣除每行所需硬幣
思路
- 同想法
這題還能用binary search
做,但反而就變困難了
Code
Neetcode大大用BS
做的
class Solution {
public int arrangeCoins(int n) {
int i = 1; // row
// Until used all the coins
while (n > 0) {
++i; // Increase the row
n -= i; // Decrease n by row
}
return i - 1;
}
}
441. Arranging Coins - Easy
https://f88083.github.io/2024/09/04/441-Arranging-Coins-Easy/