Created
January 10, 2018 13:31
-
-
Save s4553711/40172cc9faeb72fc97ff078f041009c8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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) { | |
rec[start]++; | |
rec[end]--; | |
int c = 0; | |
for(auto &r: rec) { | |
//cout << "1 > " << r.first << " - " << r.second << " c: " << c << endl; | |
c += r.second; | |
//cout << "2 > " << r.first << " - " << r.second << " c: " << c << endl; | |
if (c > 1) { | |
rec[start]--; | |
rec[end]++; | |
return false; | |
} | |
} | |
return true; | |
} | |
private: | |
map<int, int> rec; | |
}; | |
/** | |
* Your MyCalendar object will be instantiated and called as such: | |
* MyCalendar obj = new MyCalendar(); | |
* bool param_1 = obj.book(start,end); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment