1739. Building Boxes

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 1739

class Solution:
    def minimumBoxes(self, n: int) -> int:
        s, k = 0, 1
        while s + k * (k + 1) // 2 <= n:
            s += k * (k + 1) // 2
            k += 1
        k -= 1
        res = k * (k + 1) // 2
        k = 1
        while s < n:
            res += 1
            s += k
            k += 1
        return res