-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKOKO
More file actions
43 lines (30 loc) · 783 Bytes
/
Copy pathKOKO
File metadata and controls
43 lines (30 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Solution {
public int minEatingSpeed(int[] piles, int h) {
int low = 1;
int high = 0;
for (int pile : piles) {
high = Math.max(high, pile);
}
int ans = high;
while (low <= high) {
int mid = low + (high - low) / 2;
if (canFinish(piles, h, mid)) {
ans = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
return ans;
}
private boolean canFinish(int[] piles, int h, int k) {
long hours = 0;
for (int pile : piles) {
hours += (pile + k - 1) / k;
if (hours > h) {
return false;
}
}
return true;
}
}