Sharing my 580ms C++ solution


  • 0
    T
    /**
     * Definition for an interval.
     * struct Interval {
     *     int start;
     *     int end;
     *     Interval() : start(0), end(0) {}
     *     Interval(int s, int e) : start(s), end(e) {}
     * };
     */
     
    bool compareInterval(Interval I1, Interval I2)
    {
        return (I1.start < I2.start);
    }
    
    class Solution {
    public:
        bool canAttendMeetings(vector<Interval>& intervals) {
            sort(intervals.begin(), intervals.end(), compareInterval);
            for(int i=1; i<intervals.size(); i++)
                if(intervals[i].start < intervals[i-1].end)
                    return false;
                    
            return true;
        }
    };

Log in to reply
 

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