Skip to content

Commit 15e0b6c

Browse files
authored
Update building-boxes.py
1 parent a617794 commit 15e0b6c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Python/building-boxes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Time: O(1)
22
# Space: O(1)
33

4+
import math
5+
6+
47
class Solution(object):
58
def minimumBoxes(self, n):
69
"""
@@ -14,5 +17,5 @@ def minimumBoxes(self, n):
1417
# (h-1)*h*(h+1) < h^3 <= 6n < h*(h+1)*(h+2) < (h+1)^3
1518
h -= 1
1619
n -= h*(h+1)*(h+2)//6
17-
d = int(ceil((-1+sqrt(1+8*n))/2)) # find min d s.t. d*(d+1)//2 >= n
20+
d = int(math.ceil((-1+math.sqrt(1+8*n))/2)) # find min d s.t. d*(d+1)//2 >= n
1821
return h*(h+1)//2 + d

0 commit comments

Comments
 (0)