首页 > 其他 > 详细

The Skyline Problem leetcode 详解

时间:2017-01-07 21:03:15      阅读:274      评论:0      收藏:0      [点我收藏+]
技术分享

class
Solution { public: vector<pair<int, int>> getSkyline(vector<vector<int>>& buildings) { vector<pair<int, int> > h, res; multiset<int> m; int pre = 0, cur = 0; for (auto &a : buildings) { h.push_back({a[0], -a[2]}); h.push_back({a[1], a[2]}); } sort(h.begin(), h.end()); m.insert(0); for (auto &a : h) { if (a.second < 0) m.insert(-a.second); else m.erase(m.find(a.second)); cur = *prev(m.end()); if (cur != pre) { res.push_back({a.first, cur}); pre = cur; } } return res; } };

 

The Skyline Problem leetcode 详解

原文:http://www.cnblogs.com/yanchengwang/p/6260283.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!