28ms C++ Beat 100% Simple and Clear O(nlogn) Time, O (n) Space, Concise and Clear


  • 0
    F

    I feel like leetcode changed this problem's test cases or compiler or something else. I don't understand why there are so many solutions with 600 ms running time.

     struct Solution {
        int minMeetingRooms(vector<Interval>& intervals) {
            vector<pair<int, int>> times;
            for (const auto & i : intervals)
            {
                times.emplace_back(i.start, 1);
                times.emplace_back(i.end, -1);
            }
            sort(begin(times), end(times));
            int count = 0, max_overlap = 0;
            for (auto t : times)
            {
                count += t.second;
                max_overlap = max(max_overlap, count);
            }
            return max_overlap;
        }
    };

Log in to reply
 

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