clean c++ O(n) solution, but beat only 5% -.-


  • 0
    1. keep track of start and end point.
    2. value at any such point > 1 will result false.
    public:
        bool canAttendMeetings(vector<Interval>& intervals) {
            for (auto interval : intervals) {
                time[interval.start]++;
                time[interval.end]--;
            }
            int total = 0;
            for (auto t : time) {
                if ((total += t.second) > 1)
                    return false;
            }
            return true;
        }
    private:
        map<int, int> time;
    

Log in to reply
 

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