Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyCalendar {
- public:
- map<int, int> calendar;
- MyCalendar() {
- }
- bool book(int start, int end) {
- auto pos = calendar.lower_bound(start);
- if(pos != calendar.end() && pos->first < end) return false;
- if(pos != calendar.begin() && (--pos)->second > start) return false;
- calendar[start] = end;
- return true;
- }
- };
- /**
- * Your MyCalendar object will be instantiated and called as such:
- * MyCalendar* obj = new MyCalendar();
- * bool param_1 = obj->book(start,end);
- */
Advertisement
Add Comment
Please, Sign In to add comment