Re: [闲聊] 每日leetcode

楼主: DJYOMIYAHINA (通通打死)   2024-11-14 22:49:44
小看一下hint
又是binary search
我对binary search的联想力真的很不构= =
def minimizedMaximum(self, n: int, quantities: List[int]) -> int:
def canbeDistributed(k):
cnt = 0
for q in quantities:
cnt += ceil(q/k)
return cnt<=n
l,r = 1, max(quantities)
while l<r:
mid = (l+r)//2
if canbeDistributed(mid):
r = mid
else:
l = mid+1
return l

Links booklink

Contact Us: admin [ a t ] ucptt.com