Simple Java solution


  • 0
    C

    Acknowledgement: comparator code from Senpai vimukthi

    public class Solution {
        public boolean canAttendMeetings(Interval[] intervals) {
            if(intervals.length<2) return true;
            Arrays.sort(intervals, new Comparator<Interval>(){
                @Override
                public int compare(Interval lhs, Interval rhs){
                    if (lhs.start == rhs.start) return 0;
                    return lhs.start > rhs.start ? 1 : -1;
                }
            });
            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.