leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE |

0729.cpp (473B)


1 class MyCalendar { 2 typedef pair<int, int> record; 3 set<record> st; 4 5 public: 6 bool book(int estart, int eend) { 7 const record event(estart, eend); 8 const auto next = st.lower_bound(event); 9 10 if (next != end(st) && next->first < eend) return false; 11 if (next != begin(st)) { 12 const auto prv = prev(next); 13 if (prv->second > estart) return false; 14 } 15 16 st.insert(event); 17 return true; 18 } 19 };