Advertisement
nikunjsoni

731

May 26th, 2021
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. class MyCalendarTwo {
  2. public:
  3.     map<int, int> time;
  4.     MyCalendarTwo() {
  5.        
  6.     }
  7.    
  8.     bool book(int start, int end) {
  9.         time[start]++;
  10.         time[end]--;
  11.         int booked = 0;
  12.         for(auto t : time) {
  13.             booked += t.second;
  14.             if(booked == 3) {
  15.                 time[start]--;
  16.                 time[end]++;
  17.                 return false;
  18.             }
  19.         }
  20.         return true;
  21.     }
  22. };
  23.  
  24. /**
  25.  * Your MyCalendarTwo object will be instantiated and called as such:
  26.  * MyCalendarTwo* obj = new MyCalendarTwo();
  27.  * bool param_1 = obj->book(start,end);
  28.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement