C++ Solution without using sort (but same complexity)

  • 0
    bool canAttendMeetings(vector<Interval>& intervals) {
            auto mycomp = [&](const Interval& i1, const Interval& i2) {return i1.end <= i2.start;};
            set<Interval, decltype(mycomp)> myset(mycomp);
            for(auto& inter: intervals)
                if(!myset.insert(inter).second) return false;
            return true;

Log in to reply

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