Simple easy java O(n^2) solution

  • 0

    The idea is the most overlapped common time interval must be formed by two time points which appear in intervals (starts and ends). Just to take care that the time interval is real number open interval.

    public class Solution {
        public int minMeetingRooms(Interval[] intervals) {
            if(intervals.length==0) return 0;
            int ans = 1;
            for(int i=0; i<intervals.length; i++){
                int start = intervals[i].start;
                int end = intervals[i].end;
                int cntStart=0;
                int cntEnd = 0;
                for(int j=0; j<intervals.length; j++){
                    if(start>=intervals[j].start && start<intervals[j].end) cntStart++;
                    if(end<=intervals[j].end && end>intervals[j].start) cntEnd++;
                ans = Math.max(ans, cntStart);
                ans = Math.max(ans, cntEnd);
            return ans;

Log in to reply

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