Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {
- vector<pair<int, int>> evs;
- for (auto &v: buildings) {
- evs.emplace_back(v[0], v[2]);
- evs.emplace_back(v[1], -v[2]);
- }
- sort(evs.begin(), evs.end());
- multiset<int> hs = {0};
- vector<pair<int, int>> pts;
- for (auto &[x, h]: evs) {
- if (h > 0) hs.insert(h);
- else hs.erase(hs.lower_bound(-h));
- pts.emplace_back(x, *hs.rbegin());
- }
- reverse(pts.begin(), pts.end());
- pts.erase(unique(pts.begin(), pts.end(), [](auto a, auto b) { return a.first == b.first; }), pts.end());
- reverse(pts.begin(), pts.end());
- pts.erase(unique(pts.begin(), pts.end(), [](auto a, auto b) { return a.second == b.second;}), pts.end());
- vector<vector<int>> formatted;
- for (auto &[x, h]: pts)
- formatted.push_back({x, h});
- return formatted;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement