Java Solution anonymous Comparator


  • 0
    A
    public boolean canAttendMeetings(Interval[] intervals) {
        Arrays.sort(intervals, new Comparator<Interval>() {
            @Override
            public int compare(Interval a, Interval b) {
                return a.start - b.start;
            }
        });
        int end = -1;
        for(Interval interval : intervals) {
            if (interval.start < end) return false;
            end = interval.end;
        }
        return true;
    }

Log in to reply
 

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