Java O(n*k) solution, two passes, k=start -end in Interval


  • 0
    X
    public class Solution {
    public boolean canAttendMeetings(Interval[] intervals) {
        int start=Integer.MAX_VALUE;
        int end=Integer.MIN_VALUE;
        int s=0;
        int e=0;
        for(Interval i:intervals){
            start=Math.min(i.start,start);
            end=Math.max(i.end,end);
        }
        boolean[] result=new boolean[end-start+1];
        for(Interval i:intervals){
            s=i.start;
            e=i.end;
            for(int j=s;j<e;j++){
                if(result[j-start]==true )return false;
                result[j-start]=true;
            }
        }
        return true;
    }

  • 0
    C

    I got TLE. I doesn't work for the very large gap between start and end.


Log in to reply
 

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