Skip to content

Commit be895f6

Browse files
authored
Update and rename 5979-earliest-possible-day-of-full-bloom.js to 2136-earliest-possible-day-of-full-bloom.js
1 parent d238c5b commit be895f6

File tree

2 files changed

+36
-36
lines changed

2 files changed

+36
-36
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @param {number[]} plantTime
3+
* @param {number[]} growTime
4+
* @return {number}
5+
*/
6+
const earliestFullBloom = function(plantTime, growTime) {
7+
const sum = arr => arr.reduce((ac, e) => ac +e, 0)
8+
let l = 0, r = sum(plantTime) + sum(growTime)
9+
const n = plantTime.length
10+
11+
const a = []
12+
for(let i = 0; i < n; i++) {
13+
a.push([growTime[i], plantTime[i] ])
14+
}
15+
16+
a.sort((a, b) => a[0] === b[0] ? a[1] - b[1] : a[0] - b[0])
17+
a.reverse()
18+
function chk(d) {
19+
let total = -1
20+
let max_num = 0
21+
for(let i = 0; i < n; i++) {
22+
total += a[i][1]
23+
max_num = Math.max(max_num, total + a[i][0] + 1)
24+
}
25+
return max_num <= d
26+
}
27+
28+
while (l < r) {
29+
let m = ~~((l + r) / 2)
30+
if (chk(m)) r = m
31+
else l = m + 1
32+
}
33+
34+
return l
35+
};
36+

5979-earliest-possible-day-of-full-bloom.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)