C++_Sort_15ms_98.76%


  • 0

    You can just rewrite the sort function in STL, and then you could get the result.
    Code:

    class Solution {
    public:
    bool canAttendMeetings(vector<Interval>& intervals) {
        if(intervals.empty()) return true;
        
        sort(
            intervals.begin(), intervals.end(),
            [](Interval a, Interval b){
            return a.start < b.start || (a.start ==  b.start && a.end <= b.end);}
        );
        
        for(int i = 1; i < intervals.size(); ++i){
            if(intervals[i-1].end <= intervals[i].start){continue;}
            else{return false;}
        }
        return true;
    }
    };
    

    0_1476290062644_AA4A881C-D9F5-41DF-9F5C-D74F2F2A647B 2.png


Log in to reply
 

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