875. Koko Eating Bananas Medium
1/**
2 * [875] Koko Eating Bananas
3 *
4 * Koko loves to eat bananas. There are n piles of bananas, the i^th pile has piles[i] bananas. The guards have gone and will come back in h hours.
5 * Koko can decide her bananas-per-hour eating speed of k. Each hour, she chooses some pile of bananas and eats k bananas from that pile. If the pile has less than k bananas, she eats all of them instead and will not eat any more bananas during this hour.
6 * Koko likes to eat slowly but still wants to finish eating all the bananas before the guards return.
7 * Return the minimum integer k such that she can eat all the bananas within h hours.
8 *
9 * Example 1:
10 *
11 * Input: piles = [3,6,7,11], h = 8
12 * Output: 4
13 *
14 * Example 2:
15 *
16 * Input: piles = [30,11,23,4,20], h = 5
17 * Output: 30
18 *
19 * Example 3:
20 *
21 * Input: piles = [30,11,23,4,20], h = 6
22 * Output: 23
23 *
24 *
25 * Constraints:
26 *
27 * 1 <= piles.length <= 10^4
28 * piles.length <= h <= 10^9
29 * 1 <= piles[i] <= 10^9
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/koko-eating-bananas/
35// discuss: https://leetcode.com/problems/koko-eating-bananas/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn min_eating_speed(piles: Vec<i32>, h: i32) -> i32 {
41 0
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_875() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.