A different approach using JAVA


  • 0
    C
    /**
     * Definition for an interval.
     * public class Interval {
     *     int start;
     *     int end;
     *     Interval() { start = 0; end = 0; }
     *     Interval(int s, int e) { start = s; end = e; }
     * }
     */
    public class Solution
    {
        public int minMeetingRooms(Interval[] intervals)
        {
            if(intervals.length == 0)
            {
                return 0;
            }
            
            int min = Integer.MAX_VALUE;
            int max = Integer.MIN_VALUE;
            
            for(int i = 0; i < intervals.length; i++)
            {
                min = Math.min(min, intervals[i].start);
                max = Math.max(max, intervals[i].end);
            }
            
            int[] arr = new int[max + 1];
            
            max = Integer.MIN_VALUE;
            
            for(Interval inter : intervals)
            {
                for(int j = inter.start; j < inter.end; j++)
                {
                    arr[j]++;
                    max = Math.max(max, arr[j]);
                }
            }
            
            return max;
        }
    }

Log in to reply
 

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