Skip to content

Commit 61119da

Browse files
authored
Create 1482. Minimum Number of Days to Make m Bouquets
1 parent f3d4eeb commit 61119da

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution {
2+
public:
3+
int minDays(vector<int>& bloomDay, int m, int k) {
4+
int l = 1, r = 1e9;
5+
int ans = -1;
6+
while(l <= r) {
7+
int mid = l + (r - l) / 2;
8+
int consecutiveLength = 0, bonquets = 0;
9+
for(int i = 0; i < bloomDay.size(); i++) {
10+
if(bloomDay[i] <= mid) {
11+
consecutiveLength++;
12+
if(consecutiveLength >= k) {
13+
consecutiveLength = 0;
14+
bonquets++;
15+
}
16+
} else {
17+
consecutiveLength = 0;
18+
}
19+
}
20+
if(bonquets >= m) {
21+
ans = mid;
22+
r = mid - 1;
23+
} else {
24+
l = mid + 1;
25+
}
26+
}
27+
return ans;
28+
}
29+
};

0 commit comments

Comments
 (0)