my calendar ii more than 82


  • 0
    H
    class MyCalendarTwo {
    public:
        vector<pair<int,int>> singletime;  //booked once
        vector<pair<int,int>> doubletime;  //booked twice
        
        bool book(int start, int end) {
          for(pair<int,int>temp : doubletime)
          {
              //if in doubletime          return false
              if(max(temp.first,start) < min(temp.second,end))
                  return false;
          }
            for(pair<int,int>temp : singletime)
            {
                //if in singletime        put in doubletime
                if(max(temp.first,start) < min(temp.second,end))
                {
                    doubletime.push_back({max(temp.first,start),min(end,temp.second)});   
                }
            }
            //finally no matter how put in single
            singletime.push_back({start,end});
            return true;
        }
    };
    

Log in to reply
 

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