C++ 4 lines concise solution using lambda


  • 0
     bool canAttendMeetings(vector<Interval>& intervals) {
            if(intervals.size()==0) return true;
            sort(intervals.begin(),intervals.end(),[](Interval& a,Interval& b){return a.start<b.start;});
            for(int i=0;i<intervals.size()-1;i++) if(intervals[i].end>intervals[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.