C# - sort by start time, check for next starts before previous end


  • 0
    public bool CanAttendMeetings(Interval[] intervals) {
        intervals = intervals.OrderBy(x => x.start).ToArray();
        for (int i = 1; i < intervals.Length; i++)
        {
            if (intervals[i].start < intervals[i-1].end) return false;
        }
        return true;
    }

Log in to reply
 

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