C++ code below beat 100% so far, simple and easy


  • 0
    L

    below are code

    int minMeetingRooms(vector<Interval>& intervals) {
    
        sort(intervals.begin(), intervals.end(), [](const Interval& a, const Interval& b) { return a.start<b.start;});
        vector<int> rooms;
        for(const Interval& it : intervals) {
            bool newroom=true;
            for(int i=0; i < rooms.size(); ++i) {
                if(rooms[i] <= it.start) {
                    rooms[i] = it.end;
                    newroom=false;
                    break;
                }
            }
            if(newroom) { rooms.push_back(it.end); }
        }
        return rooms.size();
    
    }

  • 0
    F

    newroom variable is unnecessary in your code.


Log in to reply
 

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