public int minimumBoxes(int n) {
int x = (int) Math.cbrt(6L * n);
int ans = x * (x + 1) / 2;
int maxN = (int) ((long) x * (x + 1) * (x + 2) / 6);
if (maxN > n) {
maxN -= ans;
ans -= x;
}
return ans + (int) Math.ceil((-1 + Math.sqrt(1 + 8 * (n - maxN))) / 2);
}
2022.12.25-----leetcode.1739
最新推荐文章于 2024-07-24 22:13:06 发布