Simple and fast JAVA solution


  • 1
    X

    public class Solution {

    public int minMeetingRooms(Interval[] intervals) {
        
        if(intervals.length==0){
            return 0;
        }
        
        int len=intervals.length;
        int[] start=new int[len];
        int[] end=new int[len];
        
        for(int i=0;i<len;i++){
            start[i]=intervals[i].start;
            end[i]=intervals[i].end;
    
        
        }
        
        Arrays.sort(start);
        Arrays.sort(end);
        
        int room=1;//initial a room for meetng
        int nextEndTime=0;
        for(int i=1;i<len;i++){
            
            if(start[i]<end[nextEndTime]){
                room++;
            }
            
            else{ 
                nextEndTime++;
                }
        }
        
        return room;
        
        
    }
    

    }


Log in to reply
 

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