-
Notifications
You must be signed in to change notification settings - Fork 481
/
0218.cpp
32 lines (30 loc) · 870 Bytes
/
0218.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Solution
{
public:
vector<vector<int>> getSkyline(vector<vector<int>>& buildings)
{
vector<vector<int> > res;
vector<pair<int, int> > points;
for(const auto& it : buildings)
{
points.push_back({it[0], -it[2]});
points.push_back({it[1], it[2]});
}
sort(points.begin(), points.end());
multiset<int> height = {0};
int preHighest = 0;
int curHighest = 0;
for(const auto& co : points)
{
if(co.second < 0) height.insert(-co.second);
else height.erase(height.find(co.second));
curHighest = *height.rbegin();
if(preHighest != curHighest)
{
res.push_back({co.first, curHighest});
preHighest = curHighest;
}
}
return res;
}
};