C++ O(n^2), most straightforward method, could be improved a lot


  • 0
    J
    class Solution {
    public:
        int minMeetingRooms(vector<Interval>& intervals) {
            if(intervals.size()==0)return 0;
            sort(intervals.begin(),intervals.end(),[](const Interval &a,const Interval &b){
                if(a.start!=b.start)
                    return a.start<b.start;
                else return a.end<b.end;
            });
            int res=1;
            for(int i=1;i<intervals.size();++i){
                int t=1;
                for(int j=0;j<i;++j)
                    if(intervals[j].end>intervals[i].start)t++;
                if(res<t)res=t;
            }
            return res;
        }
    };

Log in to reply
 

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