Re: [閒聊] 每日leetcode
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
```
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 185.213.82.235 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1731592495.A.659.html
討論串 (同標題文章)
完整討論串 (本文為第 1120 之 1549 篇):