1.Meeting Rooms II

https://leetcode.com/problems/meeting-rooms-ii/

class Solution {
public:
    bool cmp(const Interval &a, const Interval &b) {
        return a.start < b.start;
    }
    int minMeetingRooms(vector& intervals) {
        sort(intervals.begin(), intervals.end(), cmp);
        priority_queue, greater> q;
        for (auto a : intervals) {
            if (!q.empty() && q.top() <= a.start) q.pop();
            q.push(a.end);
        }
        return q.size();
    }
};

你可能感兴趣的:(1.Meeting Rooms II)