# [LeetCode] Meeting Rooms 会议室

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.

For example,
Given `[[0, 30],[5, 10],[15, 20]]`,
return `false`.

```class Solution {
public:
bool canAttendMeetings(vector<Interval>& intervals) {
for (int i = 0; i < intervals.size(); ++i) {
for (int j = i + 1; j < intervals.size(); ++j) {
if ((intervals[i].start >= intervals[j].start && intervals[i].start < intervals[j].end) || (intervals[j].start >= intervals[i].start && intervals[j].start < intervals[i].end)) return false;
}
}
return true;
}
};```

```class Solution {
public:
bool canAttendMeetings(vector<Interval>& intervals) {
sort(intervals.begin(), intervals.end(), [](const Interval &a, const Interval &b){return a.start < b.start;});
for (int i = 1; i < intervals.size(); ++i) {
if (intervals[i].start < intervals[i - 1].end) {
return false;
}
}
return true;
}
};```

Merge Intervals

Meeting Rooms II

https://leetcode.com/problems/meeting-rooms/solution/

,

原文作者：Grandyang
原文地址: http://www.cnblogs.com/grandyang/p/5240774.html
本文转自网络文章，转载此文章仅为分享知识，如有侵权，请联系博主进行删除。