diff options
author | Jack Sangdahl <[email protected]> | 2025-03-10 00:36:13 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-03-10 00:36:13 -0600 |
commit | 7c60dee83b436e8e8a667bf9f191beced8de4fc3 (patch) | |
tree | eb7a24ee2067f92245c57bb118e85a1baf15df50 /other/skyline_problem.cpp | |
parent | 5d7cdc215e4ba1ec4cbb24c084cccb5e5e641468 (diff) | |
download | leetcode-7c60dee83b436e8e8a667bf9f191beced8de4fc3.tar.gz leetcode-7c60dee83b436e8e8a667bf9f191beced8de4fc3.zip |
chore: move cpp and rust code to directory
Diffstat (limited to 'other/skyline_problem.cpp')
-rw-r--r-- | other/skyline_problem.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/other/skyline_problem.cpp b/other/skyline_problem.cpp new file mode 100644 index 0000000..b19c87a --- /dev/null +++ b/other/skyline_problem.cpp @@ -0,0 +1,28 @@ +#include "leetcode.h" + +class Solution { +public: + vvd getSkyline(vvd & buildings) { + vvd ans; + map<int, vector<pair<int, int>>> mvp; + for (auto &b : buildings) { + mvp[b[0]].push_back({b[2], 0}); + mvp[b[1]].push_back({b[2], 1}); + } + multiset<int> m; + for (auto &[pos, heights] : mvp) { + for (auto &[height, type] : heights) { + if (type == 0) + m.insert(height); + else + m.erase(m.find(height)); + } + int newHeight = m.empty() ? 0 : *m.begin(); + if (!ans.empty() && ans.back()[1] == newHeight) + continue; + else + ans.push_back(vector<int>({pos, newHeight})); + } + return ans; + } +}; |