4-line clean C++ O(N*logN) solution with sorting by start time


  • 0
        bool canAttendMeetings(vector<Interval>& intervals) {
          if (intervals.empty()) return true; // no meeting? no problem!
          sort(intervals.begin(), intervals.end(), [](Interval& a, Interval& b){ return a.start < b.start; });  
          for (auto i = intervals.begin(); i < intervals.end()-1; ++i) if (i->end > (i+1)->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.