Java nlog(n) easy solution without heap


  • 3
    J
    public class Solution {
    public int minMeetingRooms(Interval[] intervals) {
        int res =0;
        int temp =0;
        int[] start = new int[intervals.length];
        int[] end = new int[intervals.length];
        for(int i= 0; i<intervals.length; i++){
            start[i] = intervals[i].start;
            end[i] = intervals[i].end;
        }
        Arrays.sort(start);
        Arrays.sort(end);
        int i=0;
        int j=0;
        while(i<start.length&&j<end.length){
            if(start[i]<end[j]){
                temp++;
                i++;
                res = Math.max(res,temp);
            }
            else{
                temp--;
                j++;
            }
        }
        return res;
    }
    

    }


  • 0
    M

    can you make a explanation about the while loop?


Log in to reply
 

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