Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. class Solution {
  2. public:
  3. vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {
  4. vector<pair<int, int>> evs;
  5. for (auto &v: buildings) {
  6. evs.emplace_back(v[0], v[2]);
  7. evs.emplace_back(v[1], -v[2]);
  8. }
  9. sort(evs.begin(), evs.end());
  10. multiset<int> hs = {0};
  11. vector<pair<int, int>> pts;
  12. for (auto &[x, h]: evs) {
  13. if (h > 0) hs.insert(h);
  14. else hs.erase(hs.lower_bound(-h));
  15. pts.emplace_back(x, *hs.rbegin());
  16. }
  17. reverse(pts.begin(), pts.end());
  18. pts.erase(unique(pts.begin(), pts.end(), [](auto a, auto b) { return a.first == b.first; }), pts.end());
  19. reverse(pts.begin(), pts.end());
  20. pts.erase(unique(pts.begin(), pts.end(), [](auto a, auto b) { return a.second == b.second;}), pts.end());
  21. vector<vector<int>> formatted;
  22. for (auto &[x, h]: pts)
  23. formatted.push_back({x, h});
  24. return formatted;
  25. }
  26. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement