leetcode252. meeting room

Given array of a schedule of meetings, each meeting will include the start time and end time of [[s1, e1], [s2, e2], ...] (si <ei), you can determine whether a person participate in all the meetings there.

Example 1:

Input: [[0,30], [5,10], [15,20]]
Output: false
Example 2:

Input: [[7,10], [2,4]]
Output: true

Idea: according to the start time of ordering, each conference to determine whether there is overlap time can be.

class Solution {
    public boolean canAttendMeetings(int[][] intervals) {
       if(intervals == null || intervals.length==0)return true;
        Arrays.sort(intervals, new Comparator<int[]>() {
			@Override
			public int compare(int[] o1, int[] o2) {
				return o1[0] - o2[0];
			}
		});
        for(int i=0;i+1<intervals.length;i++){
            if(intervals[i][1]>intervals[i+1][0])return false;
        }
        return true;
    }
}

 

Published 473 original articles · won praise 10000 + · Views 1.1 million +

Guess you like

Origin blog.csdn.net/hebtu666/article/details/104096888