-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path2251.cpp
More file actions
24 lines (21 loc) · 819 Bytes
/
Copy path2251.cpp
File metadata and controls
24 lines (21 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution {
public:
vector<int> fullBloomFlowers(const vector<vector<int>> &flowers, const vector<int> &people) const {
vector<int> start, finish, res;
start.reserve(flowers.size());
finish.reserve(flowers.size());
for (const auto &flower : flowers) {
start.push_back(flower[0]);
finish.push_back(flower[1] + 1);
}
sort(begin(start), end(start));
sort(begin(finish), end(finish));
res.reserve(people.size());
for (const int person : people) {
const int left = upper_bound(begin(start), end(start), person) - begin(start);
const int right = upper_bound(begin(finish), end(finish), person) - begin(finish);
res.push_back(left - right);
}
return res;
}
};