My java solution

  • 1
    public boolean canAttendMeetings(Interval[] intervals) {
        if(intervals.length < 2) return true;
        Arrays.sort(intervals, new IntervalComparator());
        Interval prev = intervals[0];
        for(int i=1; i<intervals.length; i++) {
            if(intervals[i].start < prev.end) return false;
            prev = intervals[i];
        return true;
    class IntervalComparator implements Comparator<Interval> {
        public int compare(Interval m, Interval n) {
            if(m.start == n.start) return m.end-n.end;
            return m.start-n.start;

Log in to reply

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