
解題思路
在看了一位博主的插旗法介紹后,三道題輕輕松松解決,等于是三題一解,思路上都是插旗法,并且代碼上幾乎沒什么變化,所以,,,這是困難題?感興趣的同學可以從鏈接進去了解,我的部分理解也放在了評論區,代碼如下:
代碼
class MyCalendarThree {
public:
map<int, int> mp;
MyCalendarThree() {
}
int book(int start, int end) {
mp[start] += 1;
mp[end] -= 1;
int ans = 0, cur = 0;
for(auto& [a, b] : mp) {
cur += b;
ans = max(ans, cur);
}
return ans;
}
};
/**
* Your MyCalendarThree object will be instantiated and called as such:
* MyCalendarThree* obj = new MyCalendarThree();
* int param_1 = obj->book(start,end);
*/
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/354544.html
標籤:其他
上一篇:Leetcode 7. 整數反轉
