1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-04 23:11:41 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/算法题(国内版)/problem (Chinese)/我的日程安排表 III [my-calendar-iii].html

41 lines
1.9 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p><code>k</code> 个日程安排有一些时间上的交叉时(例如 <code>k</code> 个日程安排都在同一时间内),就会产生 <code>k</code> 次预订。</p>
<p>给你一些日程安排 <code>[start, end)</code> ,请你在每个日程安排添加后,返回一个整数 <code>k</code> ,表示所有先前日程安排会产生的最大 <code>k</code> 次预订。</p>
<p>实现一个 <code>MyCalendarThree</code> 类来存放你的日程安排,你可以一直添加新的日程安排。</p>
<ul>
<li><code>MyCalendarThree()</code> 初始化对象。</li>
<li><code>int book(int start, int end)</code> 返回一个整数 <code>k</code> ,表示日历中存在的 <code>k</code> 次预订的最大值。</li>
</ul>
<p> </p>
<p><strong>示例:</strong></p>
<pre>
<strong>输入:</strong>
["MyCalendarThree", "book", "book", "book", "book", "book", "book"]
[[], [10, 20], [50, 60], [10, 40], [5, 15], [5, 10], [25, 55]]
<strong>输出:</strong>
[null, 1, 1, 2, 3, 3, 3]
<strong>解释:</strong>
MyCalendarThree myCalendarThree = new MyCalendarThree();
myCalendarThree.book(10, 20); // 返回 1 ,第一个日程安排可以预订并且不存在相交,所以最大 k 次预订是 1 次预订。
myCalendarThree.book(50, 60); // 返回 1 ,第二个日程安排可以预订并且不存在相交,所以最大 k 次预订是 1 次预订。
myCalendarThree.book(10, 40); // 返回 2 ,第三个日程安排 [10, 40) 与第一个日程安排相交,所以最大 k 次预订是 2 次预订。
myCalendarThree.book(5, 15); // 返回 3 ,剩下的日程安排的最大 k 次预订是 3 次预订。
myCalendarThree.book(5, 10); // 返回 3
myCalendarThree.book(25, 55); // 返回 3
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 <= start < end <= 10<sup>9</sup></code></li>
<li>每个测试用例,调用 <code>book</code> 函数最多不超过 <code>400</code></li>
</ul>