C++ 5 lines


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

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.