Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int minEatingSpeed(int[] piles, int h) {
- int left = 1;
- int right = 1000000000;
- while(left <= right){
- int mid = left + (right - left) / 2;
- if(canEatInTime(piles, mid, h)) right = mid - 1;
- else left = mid + 1;
- }
- return left;
- }
- public boolean canEatInTime(int piles[], int k, int h){
- int hours = 0;
- for(int pile : piles){
- int div = pile / k;
- hours += div;
- if(pile % k != 0) hours++;
- }
- return hours <= h;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement