Skip to content

Latest commit

 

History

History

252

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

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

Companies:
Amazon, Facebook

Related Topics:
Sort

Similar Questions:

Solution 1.

// OJ: https://leetcode.com/problems/meeting-rooms/
// Author: github.com/lzl124631x
// Time: O(NlogN)
// Space: O(1)
class Solution {
public:
    bool canAttendMeetings(vector<Interval>& intervals) {
        sort(intervals.begin(), intervals.end(), [&](Interval &a, 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;
    }
};