-
Notifications
You must be signed in to change notification settings - Fork 19
/
The Skyline Problem.cpp
36 lines (33 loc) · 985 Bytes
/
The Skyline Problem.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
33
34
35
36
class Solution {
public:
vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {
map<int, int>::iterator cit;
vector<vector<int>> res;
map<int, vector<int>> q;
map<int, int> c;
int curth = 0;
c[0] = 1;
for(auto building: buildings){
q[building[0]].push_back(building[2]);
q[building[1]].push_back(-building[2]);
}
for(auto i: q){
for(auto o: i.second){
if(o > 0){
c[o]++;
}else{
o = -o;
if(--c[o] == 0){
cit = c.find(o);
c.erase(cit);
}
}
}
if((*c.rbegin()).first != curth){
curth =(*c.rbegin()).first;
res.push_back({i.first, curth});
}
}
return res;
}
};