-
Notifications
You must be signed in to change notification settings - Fork 2
/
q0875.py
32 lines (28 loc) · 821 Bytes
/
q0875.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/python3
from typing import List
class Solution:
def minEatingSpeed(self, piles: List[int], H: int) -> int:
def vaild(number_try):
count = 0
for number in piles:
count += number // number_try
if number % number_try > 0:
count += 1
return count <= H
maxVal = piles[0]
for number in piles:
if maxVal < number:
maxVal = number
if H == len(piles):
return maxVal
left = 1
right = maxVal
result = 0
while left <= right:
mid = (left + right) // 2
if vaild(mid):
result = mid
right = mid - 1
else:
left = mid + 1
return result