Advertisement
serega1112

LC 1283

Dec 6th, 2020
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. class Solution:
  2.     def smallestDivisor(self, nums: List[int], threshold: int) -> int:
  3.        
  4.         def check(divisor):
  5.             res = 0
  6.             for num in nums:
  7.                 res += math.ceil(num / divisor)
  8.             return res <= threshold
  9.        
  10.         l = 0
  11.         r = max(nums)
  12.        
  13.         while r - l > 1:
  14.             g = l + (r - l) // 2
  15.             if check(g):
  16.                 r = g
  17.             else:
  18.                 l = g
  19.                
  20.         return r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement