题目描述:
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), determine if a person could attend all meetings.
Example 1:
Input: [[0,30],[5,10],[15,20]]
Output: false
Example 2:
Input: [[7,10],[2,4]]
Output: true
class Solution {
public:
static bool comp(Interval a, Interval b)
{
if(a.start<b.start) return true;
else return false;
}
bool canAttendMeetings(vector<Interval>& intervals) {
sort(intervals.begin(),intervals.end(),comp);
int cur_end=INT_MIN;
for(auto i:intervals)
{
if(i.start<cur_end) return false;
else cur_end=i.end;
}
return true;
}
};
本文介绍了一种用于检测会议时间是否冲突的算法。通过将会议时间区间按开始时间排序,并检查相邻会议是否有重叠,从而判断一个人是否可以参加所有预定的会议。此算法适用于日程安排、资源分配等场景。
1473

被折叠的 条评论
为什么被折叠?



