做题博客链接
https://blog.csdn.net/qq_43349112/article/details/108542248
题目链接
https://leetcode-cn.com/problems/meeting-rooms/
描述
给定一个会议时间安排的数组 intervals ,每个会议时间都会包括开始和结束的时间 intervals[i] = [starti,
endi] ,请你判断一个人是否能够参加这里面的全部会议。
提示:
0 <= intervals.length <= 104
intervals[i].length == 2
0 <= starti < endi <= 106
示例
示例 1:
输入:intervals = [[0,30],[5,10],[15,20]]
输出:false
示例 2:
输入:intervals = [[7,10],[2,4]]
输出:true
初始代码模板
class Solution {
public boolean canAttendMeetings(int[][] intervals) {
}
}
代码
按照会议的起始时间进行升序排序
class Solution {
public boolean canAttendMeetings(int[][] intervals) {
Arrays.sort(intervals, (o1, o2) -> (o1[0] == o2[0] ? o1[1] - o2[1] : o1[0] - o2[0]));
for (int i = 1; i < intervals.length; i++) {
if (intervals[i][0] < intervals[i - 1][1]) {
return false;
}
}
return true;
}
}