2
public int earliestFullBloom(int[] plantTime, int[] growTime) {3
int n = plantTime.length;4
int[][] plants = new int[n][2];5
int totalPlantTime = 0;6
for (int i = 0; i < n; i++) {7
plants[i] = new int[] {plantTime[i], growTime[i]};8
totalPlantTime += plantTime[i];10
// Sort plants by grow time.11
// The plant with fewer grow time can be planted at the end.12
Arrays.sort(plants, (a, b) -> a[1] - b[1]);13
// Max grow + plant time15
for (int[] plant : plants) {16
maxTime = Math.max(maxTime, totalPlantTime + plant[1]);17
// After putting this plant at the end of the chain,18
// we can take the current plant time out of the total plant time19
totalPlantTime -= plant[0];