题意:求多少各连续自然数之和小于n。
思路:求和公式。
class Solution {
public:
int arrangeCoins(int n) {
double tempn, tempx;
tempn = n;
tempx = sqrt(2 * tempn + 0.25) - 0.5;
return floor(tempx);
}
};题意:求多少各连续自然数之和小于n。
思路:求和公式。
class Solution {
public:
int arrangeCoins(int n) {
double tempn, tempx;
tempn = n;
tempx = sqrt(2 * tempn + 0.25) - 0.5;
return floor(tempx);
}
};
被折叠的 条评论
为什么被折叠?