LeetCode刷题实战252:会议室
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.
示例
示例 1:
输入: [[0,30],[5,10],[15,20]]
输出: false
示例 2:
输入: [[7,10],[2,4]]
输出: true
解题
class Solution { //C++
public:
bool canAttendMeetings(vector<vector<int>>& intervals) {
sort(intervals.begin(), intervals.end(),[&](auto a, auto b){
return a[0] < b[0];
});
for(int i = 1; i < intervals.size(); ++i)
{
if(intervals[i-1][1] > intervals[i][0])
return false;
}
return true;
}
};
评论