1739. 放置盒子
小学数学题了快
yxc题解
class Solution {
public:
int minimumBoxes(int n) {
int k = 1;
int sum = 0;
while (sum + (k + 1) * k / 2 <= n) {
sum += (k + 1) * k / 2;
k++;
}
int res = k * (k - 1) / 2;
k = 1;
while (sum < n) {
sum += k;
k++;
res++;
}
return res;
}
};
网友评论