Re: [闲聊] 每日leetcode

楼主: dont   2024-11-14 21:54:52
2064. Minimized Maximum of Products Distributed to Any Store
## 思路
对答案范围做Binary Search
## Code
```python
class Solution:
def minimizedMaximum(self, n: int, quantities: List[int]) -> int:
res = 0
def check(val):
count = 0
for quantity in quantities:
count += ceil(quantity / val)
if count > n:
return False
return True
left, right = 1, max(quantities)
while left <= right:
mid = (left + right) // 2
if check(mid):
res = mid
right = mid - 1
else:
left = mid + 1
return res
```

Links booklink

Contact Us: admin [ a t ] ucptt.com