Skip to content
Rain Hu's Workspace
Go back

[LeetCode] 2136. Earliest Possible Day of Full Bloom

Rain Hu

2136. Earliest Possible Day of Full Bloom


一、題目

You have n flower seeds. Every seed must be planted first before it can begin to grow, then bloom. Planting a seed take time and so does the growth of a seed. You are given two 0-indexed integer arrays plantTime and growTime, of length n each:

Example 1:
growplant1

Example 2: growplant2

Example 3:

Constraints:


二、分析

growplant

三、解題

1. Greedy

int earliestFullBloom(vector<int>& plantTime, vector<int>& growTime) {
    vector<pair<int, int>> v;
    for (int i = 0; i < plantTime.size(); ++i)
        v.push_back({growTime[i], plantTime[i]});
    sort(begin(v), end(v));
    int res = 0;
    for (auto [g, p] : v)
        res = max(res, g) + p;
    return res;
}

回目錄 Catalog


Share this post on:

Previous
[LeetCode] 2953. Count Complete Substrings
Next
[LeetCode] 2156. Find Substring With Given Hash Value