您当前的位置: 首页 > 

对方正在debug

暂无认证

  • 3浏览

    0关注

    399博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

天际线问题(扫描线)

对方正在debug 发布时间:2020-03-18 09:16:58 ,浏览量:3

题目:https://leetcode-cn.com/problems/the-skyline-problem/ 代码:https://leetcode-cn.com/problems/the-skyline-problem/solution/218tian-ji-xian-wen-ti-sao-miao-xian-fa-by-ivan_al/

class Solution {
public:
    vector getSkyline(vector& buildings) {
        vector h;
        multiset m;
        vector res;

        //1、将每一个建筑分成“两个部分”,例如:[2,9,10]可以转换成[2,-10][9,10],我们用负值来表示左边界
        for(const auto& b:buildings)
        {
            h.push_back({b[0], -b[2]});
            h.push_back({b[1], b[2]});
        }

        //2、根据x值对分段进行排序
        sort(h.begin(),h.end());
        int prev = 0, cur = 0;
        m.insert(0);

        //3、遍历
        for (auto i:h)
        {
            if (i.second             
关注
打赏
1664895754
查看更多评论
0.0372s