Skip to content

Commit 16aea1a

Browse files
authored
Create Solution.java
1 parent 66ffd3f commit 16aea1a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int minEatingSpeed(int[] piles, int H) {
3+
int l = 1, r = 1000000000;
4+
while (l < r) {
5+
int mid = l + r >>> 1;
6+
if (check(piles, H, mid)) r = mid;
7+
else l = mid + 1;
8+
}
9+
return r;
10+
}
11+
12+
private boolean check(int[] piles, int h, int k) {
13+
int cnt = 0;
14+
for (int pile : piles) {
15+
cnt += (pile - 1) / k + 1;
16+
}
17+
return cnt <= h;
18+
}
19+
}

0 commit comments

Comments
 (0)