Simple Java Solution


  • 0
    S
    public class Solution {
        public boolean canAttendMeetings(Interval[] intervals) {
            if(intervals == null || intervals.length == 0){
                return true;
            }
            
            Arrays.sort(intervals, new Comparator<Interval>(){
                @Override
                public int compare(Interval int1, Interval int2) {
                    return Integer.compare(int1.start, int2.start);
                }
            });
            
            for(int i=1; i<intervals.length; i++) {
                if(intervals[i-1].end > intervals[i].start) {
                    return false;
                }
            }
            
            return true;
        }
    }

Log in to reply
 

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