-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path2136. Earliest Possible Day of Full Bloom.java
48 lines (48 loc) · 1.65 KB
/
2136. Earliest Possible Day of Full Bloom.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
43
44
45
46
47
48
class Solution {
private class PlantInfo implements Comparable<PlantInfo> {
int plantTime;
int growTime;
public PlantInfo(int plantTime, int growTime) {
this.plantTime = plantTime;
this.growTime = growTime;
}
@Override
public String toString() {
return "PlantInfo [plantTime=" + plantTime + ", growTime=" + growTime + "]";
}
@Override
public int compareTo(PlantInfo o) {
// TODO Auto-generated method stub
if (this.growTime == o.growTime) {
return o.plantTime - this.plantTime;
}
Integer pt = o.growTime;
return pt.compareTo(this.growTime);
}
}
public int earliestFullBloom(int[] plantTime, int[] growTime) {
List<PlantInfo> plants = new ArrayList<>();
for (int i = 0; i < plantTime.length; i++) {
plants.add(new PlantInfo(plantTime[i], growTime[i]));
}
int atleastDays = 0;
// Sort based on plattime and growtime
Collections.sort(plants);
// System.out.println(plants);
for (int i = 0, plantsum = 0; i < plants.size(); i++) {
PlantInfo plant = plants.get(i);
int elapsedTimeToBlossom = plant.plantTime + plant.growTime + plantsum;
atleastDays = Math.max(atleastDays, elapsedTimeToBlossom);
plantsum += plant.plantTime;
}
return atleastDays;
}
}