diff --git a/LeetCode-CN/253.cpp b/LeetCode-CN/253.cpp new file mode 100644 index 0000000..d38e47d --- /dev/null +++ b/LeetCode-CN/253.cpp @@ -0,0 +1,34 @@ +class Solution { +public: + int minMeetingRooms(vector>& intervals) { + vector starts, ends; + for (auto& vec : intervals) { + starts.push_back(vec[0]); + ends.push_back(vec[1]); + } + sort(starts.begin(), starts.end()); + sort(ends.begin(), ends.end()); + + int needRoom = 0; + int maxRoom = 0; + for (int i = 0, j = 0; i < starts.size() && j < ends.size();) { + if (starts[i] < ends[j]) { + needRoom++; + maxRoom = max(maxRoom, needRoom); + i++; + continue; + } + + if (starts[i] > ends[j]) { + needRoom--; + j++; + continue; + } + + i++; + j++; + } + + return maxRoom; + } +};