Skip to content

Commit a9827ce

Browse files
authored
Create LeetCode_875_KokoEatingBananas.java
1 parent 82926b4 commit a9827ce

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public int minEatingSpeed(int[] piles, int h) {
3+
int left = 1;
4+
int right = 0;
5+
6+
for (int pile : piles) {
7+
right = Math.max(right, pile);
8+
}
9+
10+
while (left <= right) {
11+
int mid = left + (right - left) / 2;
12+
13+
int count = 0;
14+
for (int pile : piles) {
15+
count += Math.ceil((double) pile / mid);
16+
}
17+
18+
if (count <= h) {
19+
right = mid - 1;
20+
} else {
21+
left = mid + 1;
22+
}
23+
}
24+
25+
return left;
26+
}
27+
}

0 commit comments

Comments
 (0)