252 - Meeting Rooms

解法一 - Merge Interval 概念

基本上只要先照開始時間 sort 過,剩下就看看有沒有 overlap 就好,只要 overlap 就 return false。

class Solution {
public:
    bool canAttendMeetings(vector<vector<int>>& intervals) {
        if(intervals.empty()) {
            return true;
        }

        sort(intervals.begin(),intervals.end(),[](vector<int>a, vector<int>b){ 
            return a[0] < b[0];
        });

        for(int i = 0; i < intervals.size() - 1; ++i)
        {
            if(intervals[i][1] > intervals[i+1][0]) {
                return false;
            }
        }

        return true;
    }
};

results matching ""

    No results matching ""