Javascript Solution with steps

  • 0
    var canAttendMeetings = function(intervals) {
        intervals.sort(function(a, b) { // sort intervals incase first set of 
                                        // meeting times is in the back
            return a.start - b.start;
        for( var i=0; i<intervals.length-1; i++ ){ 
        // loop through intervals and stop right before the last 
        // interval, to save step cuz our check involves checking next interval
            if( intervals[i].end > intervals[i+1].start ) return false; 
            // if the end time is greater than the next interval's
            // start time it has to be false
        return true; // if there aren't any crossing intervals, its true

Log in to reply

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