Skip to content

Commit

Permalink
Create Koko Eating Bananas.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayu-99 authored Jan 20, 2022
1 parent 369a1bf commit af18f92
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Leetcode Challenge/January/Java/Koko Eating Bananas.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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;
}
}

0 comments on commit af18f92

Please sign in to comment.