intbook(int start, int end){ int ans = 0; int maxBook = 0; cnt[start]++; cnt[end]--; for (auto &[_, freq] : cnt) { //根据差分数组还原原来数组的值,用于下面求最大值 maxBook += freq; //更新最大预定值; ans = max(maxBook, ans); } return ans; } private: //构建差分数组 map<int, int> cnt;//不能是umap };
/** * Your MyCalendarThree object will be instantiated and called as such: * MyCalendarThree* obj = new MyCalendarThree(); * int param_1 = obj->book(start,end); */