class Solution {
public:
int minEatingSpeed(vector<int> &piles, int h) {
int left = 1, right = 1000000000;
while (left < right) {
int middle = left + (right - left) / 2;
if (isPossible(piles, middle , h)) {
// Koko eats too fast.
right = middle;
} else {
left = middle + 1;
}
}
return left;
}
private:
bool isPossible(vector<int> &piles, int k, int h) {
int time = 0;
for (auto &bananas : piles) {
time = time + bananas / k;
if (bananas % k) {
++time;
}
}
return time <= h;
}
};
piles
.
piles
.
My Solution Solution 1: DFS (recursion) The Key Idea for Solving This Coding Question C++ Code /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right;
Jun 6, 2025MyCircularQueueO(k)
Apr 20, 2025O(m)
Mar 4, 2025O(n)n is the length of nums.
Feb 19, 2025or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up