1
class Solution {
2
public:
3
vector<vector<int>> getSkyline(vector<vector<int>> &buildings) {
4
priority_queue<pair<int, int>> pq;
5
vector<int> co;
6
for (auto b : buildings) {
7
co.push_back(b[0]);
8
co.push_back(b[1]);
9
}
10
sort(co.begin(), co.end());
11
int m = unique(co.begin(), co.end()) - co.begin();
12
int j = 0, preH = 0;
13
vector<vector<int>> ans;
14
for (int i = 0; i < m; i++) {
15
while (j < buildings.size() && buildings[j][0] <= co[i])
16
pq.push(make_pair(buildings[j][2], buildings[j][1])), j++;
17
while (!pq.empty() && pq.top().second <= co[i]) pq.pop();
18
int nowH = pq.empty() ? 0 : pq.top().first;
19
if (nowH != preH) {
20
ans.push_back({co[i], nowH});
21
preH = nowH;
22
}
23
}
24
return ans;
25
}
26
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0