Skip to content

Commit 72d19d7

Browse files
authored
Create minimum-limit-of-balls-in-a-bag.py
1 parent 3d0b9a3 commit 72d19d7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Time: O(nlogn)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def minimumSize(self, nums, maxOperations):
6+
"""
7+
:type nums: List[int]
8+
:type maxOperations: int
9+
:rtype: int
10+
"""
11+
def check(nums, maxOperations, x):
12+
return sum((num+x-1)//x-1 for num in nums) <= maxOperations
13+
14+
left, right = 1, max(nums)
15+
while left <= right:
16+
mid = left + (right-left)//2
17+
if check(nums, maxOperations, mid):
18+
right = mid-1
19+
else:
20+
left = mid+1
21+
return left

0 commit comments

Comments
 (0)