C++ 580ms simple implementation using priority_queue


  • 0
    R
    class Solution {
    public:
        int minMeetingRooms(vector<Interval>& intervals) {
            sort(intervals.begin(), intervals.end(), [](Interval &a, Interval &b) { return a.start < b.start; });
            priority_queue<int, vector<int>, greater<int>> end_pq;
            int count = 0, result = 0;
            for (Interval elem : intervals) {
                while (!end_pq.empty() && end_pq.top() <= elem.start) {
                    end_pq.pop();
                    --count;
                }
                end_pq.push(elem.end);
                ++count;
                if (count > result) result = count;
            }
            return result;
        }
    };

Log in to reply
 

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