C++, unordered_map, Beats 100% of c++ Solutions.


  • 0
    R
    static bool comp(Interval A, Interval B)
    {
        return A.start<B.start;
    }
    
    int minMeetingRooms(vector<Interval>& intervals) 
    {
        if(intervals.size() == 0) return 0;
        unordered_map<int,int>hashT;
        
        sort(intervals.begin(),intervals.end(),comp);
        int cnt = 0;
        hashT[0] = intervals[0].end;
        
        for(int i=1;i<intervals.size();i++)
        {
            bool flag = false;
            for(int j=0 ; j<=cnt ; j++)
            {
                if(intervals[i].start >= hashT[j])
                {
                    flag = true;
                    hashT[j] = intervals[i].end;
                    break;
                }
            }
            if(flag == false)
            {
                cnt++;
                hashT[cnt] = intervals[i].end;
            }
        }
        return cnt+1;
    }

Log in to reply
 

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