# 1283. Find the Smallest Divisor Given a Threshold ###### tags: `Leetcode` `Medium` `Binary Search` Link: https://leetcode.com/problems/find-the-smallest-divisor-given-a-threshold/ ## 思路 $O(NlogM)$ $O(1)$ ## Code ```java= class Solution { public int smallestDivisor(int[] nums, int threshold) { int max = 0; for(int num:nums) max = Math.max(max, num); int start=1, end=max; while(start<end){ int mid = start+(end-start)/2, sum=0; for(int num:nums) sum += (num+mid-1)/mid; if(sum>threshold){ start = mid+1; } else end = mid; } return start; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up