This is another chance to use java 8 stream


  • 2
    F

    Functional programming makes the code quite concise and without boilerplate code

    public class Solution {
        public boolean canAttendMeetings(Interval[] intervals) {
            if(intervals == null || intervals.length==0){
                return true;
            }
            Arrays.sort(intervals, (x,y)->x.start-y.start);
            return !IntStream.range(1, intervals.length).anyMatch(i->intervals[i].start<intervals[i-1].end);
        }    
    }

Log in to reply
 

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