Interval scheduling problem


  • 0
    Y

    The basic idea is for each room, we count how many rooms are overlapped with it.

    public class Solution {
        public int minMeetingRooms(Interval[] intervals) {
            if (intervals == null || intervals.length == 0) return 0;
            int max = 1;
            Arrays.sort(intervals, new Comparator<Interval>() {
                public int compare (Interval a, Interval b) {
                    return a.end - b.end;
                }
            });
            for (int i = 0; i < intervals.length; i++) {
                int count = 1;
                for (int j = i + 1; j < intervals.length; j++) {
                    if (intervals[j].start < intervals[i].end) {
                        count++;
                    }
                    max = Math.max(max, count);
                }
            }
            return max;
        }
    }

Log in to reply
 

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