This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyCalendar { | |
public: | |
MyCalendar() { | |
} | |
bool book(int start, int end) { | |
if(m_tree.empty()){ m_tree[start] = end; return true; } | |
auto iter = m_tree.lower_bound(end); | |
if(iter == m_tree.begin()){ m_tree[start] = end; return true; } | |
--iter; | |
if(iter->second <= start) | |
{ | |
m_tree[start] = end; | |
return true; | |
} | |
else return false; | |
} | |
private: | |
map<int, int> m_tree; | |
}; | |
/** | |
* Your MyCalendar object will be instantiated and called as such: | |
* MyCalendar obj = new MyCalendar(); | |
* bool param_1 = obj.book(start,end); | |
*/ |
No comments:
Post a Comment