Re: [閒聊] 每日leetcode

看板Marginalman作者 (dont)時間1年前 (2024/11/14 21:54), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1120/1549 (看更多)
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
文章代碼(AID): #1dDW4lPP (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1dDW4lPP (Marginalman)