Leetcode 252 Solution

This article provides solution to leetcode question 252 (meeting-rooms)

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

Solution

/**
 * Definition for an interval.
 * struct Interval {
 *     int start;
 *     int end;
 *     Interval() : start(0), end(0) {}
 *     Interval(int s, int e) : start(s), end(e) {}
 * };
 */
class Solution {
public:
    bool canAttendMeetings(vector<Interval>& intervals) {
        sort(intervals.begin(), intervals.end(), [] (Interval& i1, Interval& i2) { return i1.start < i2.start; });

        for (int i = 1; i < intervals.size(); i++)
            if (intervals[i].start < intervals[i - 1].end)
                return false;

        return true;
    }
};