-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaily173.java
42 lines (38 loc) · 987 Bytes
/
daily173.java
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
// Solution 1 - NO ATTEMPTED SOLUTION
class Solution {
public int minimumSize(int[] nums, int maxOps) {
/*
always try to split the bag with most marbles
if even number, split in half
if odd, split by ???
9 | 2
4, 5
4, 2, 3
*/
return 0;
}
}
// Solution 2
class Solution {
public int minimumSize(int[] nums, int maxOps) {
/*
always try to split the bag with most marbles
if even number, split in half
if odd, split by ???
9 | 2
4, 5
4, 2, 3
*/
int low = 1, high = Arrays.stream(nums).max().getAsInt();
while (low < high) {
int mid = (low + high) / 2;
int ops = 0;
for (int n : nums) {
ops += (n - 1) / mid;
}
if (ops <= maxOps) high = mid;
else low = mid + 1;
}
return high;
}
}