# 1482. Minimum Number of Days to Make m Bouquets
###### tags: `Leetcode` `Medium` `Binary Search`
Link: https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets/
## 思路 $O(Nlog(max(bloomDay)))$ $O(1)$
## Code
```java=
class Solution {
public int minDays(int[] bloomDay, int m, int k) {
if(bloomDay.length < m*k) return -1;
int max = 0, min = Integer.MAX_VALUE;
for(int day:bloomDay){
max = Math.max(max, day);
min = Math.min(min, day);
}
int start = min, end = max;
while(start<end){
int mid = start+(end-start)/2;
int bouquet = computeDays(bloomDay, k, mid);
if(bouquet<m){
start = mid+1;
}
else end = mid;
}
return start;
}
private int computeDays(int[] bloomDay, int k, int day){
int bouquet = 0;
int currFlower = 0;
for(int bloom:bloomDay){
if(bloom>day){
currFlower = 0;
}
else{
currFlower++;
if(currFlower>=k){
currFlower = 0;
bouquet++;
}
}
}
return bouquet;
}
}
```