c++ clear code


  • 0
    X
    class Solution {
    public:
        vector<pair<int, int>> getSkyline(vector<vector<int>>& buildings) {
            multimap<int, int> points;
            for(vector<int>& i : buildings){
                points.insert(pair<int, int>(i[0], i[2]));
                points.insert(pair<int, int>(i[1], -i[2]));
            }
            multiset<int> s{0};
            map<int, int> r;
            for(const pair<int, int>& i : points){
                if(i.second > 0){
                    s.insert(i.second);
                }else{
                    s.erase(s.find(-i.second));
                }
                r[i.first] = *(s.rbegin());
            }
            vector<pair<int, int>> ans;
            pair<int, int> pre(-1, -1);
            for(const pair<int, int>& i : r){
                if(i.second == pre.second){
                    continue;
                }
                pre = i;
                ans.push_back(pair<int, int>(i.first, i.second));
            }
            return ans;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.