1283. 使结果不超过阈值的最小除数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution:
def smallestDivisor(self, nums: List[int], threshold: int) -> int:
def search_II(check) ->int: # 二分法目标:找除数
nums.sort()
left = 1
right = nums[len(nums)-1]
while left<=right:
mid = (left+right)>>1
if check(mid):
right = mid-1
else:
left = mid+1
return left
def check(x) ->bool:
ans = 0
for i in nums:
if i%x!=0:
ans += i//x + 1
else:
ans += i//x
print(x,"is x",ans,"is sum")
return ans <= threshold
return search_II(check)