Skip to content

Commit 1dac704

Browse files
authored
Create Koko Eating Bananas.py
1 parent 81f6aed commit 1dac704

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'''
2+
3+
Problem 875 | Koko Eating Bananas
4+
https://leetcode.com/problems/koko-eating-bananas/
5+
6+
'''
7+
8+
class Solution:
9+
def minEatingSpeed(self, piles: List[int], h: int) -> int:
10+
l, r = 1, max(piles)
11+
res = r
12+
while l <= r:
13+
k = (l + r) // 2
14+
hours = 0
15+
for p in piles:
16+
hours += math.ceil(p/k)
17+
if hours <= h:
18+
res = min(k, res)
19+
r = k - 1
20+
else:
21+
l = k + 1
22+
return res
23+

0 commit comments

Comments
 (0)