732. My schedule Table III
topic
Thinking
Boundary recording, scanning, looking for the maximum.
Code
class MyCalendarThree {
public:
map<int,int> mp;
MyCalendarThree() {
}
int book(int start, int end) {
mp[start]+=1;
mp[end]-=1;
int ans=0,sum=0;
for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++)
{
sum+=it->second;
if(ans<sum) ans=sum;
}
return ans;
}
};
/**
* Your MyCalendarThree object will be instantiated and called as such:
* MyCalendarThree* obj = new MyCalendarThree();
* int param_1 = obj->book(start,end);
*/