My simple c++ solution


  • 0
    K
    class compare{
    public:
     bool operator()(Interval a, Interval b)
     {
         return a.start < b.start;
     }
     };
    class Solution {
    public:
    int minMeetingRooms(vector<Interval>& intervals) {
        if(intervals.size() <=1)return intervals.size();
        sort(intervals.begin(), intervals.end(), compare());
        vector<Interval>res;
        for(auto & data : intervals){
            bool overlap=true;
            if(res.empty()){
                res.push_back(data);
                continue;
            }
            for(auto & meeting : res){
                if(data.start >= meeting.end){
                    meeting.start=data.start;
                    meeting.end=data.end;
                    overlap=false;
                    break;
                }
            }
            if(overlap)res.push_back(data);
        }
        return res.size();
    }
    };

Log in to reply
 

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