mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-12 10:51:42 +08:00
批量更新数据
This commit is contained in:
@@ -1,30 +1,35 @@
|
||||
<p>实现一个 <code>MyCalendar</code> 类来存放你的日程安排。如果要添加的时间内不会导致三重预订时,则可以存储这个新的日程安排。</p>
|
||||
<p>实现一个程序来存放你的日程安排。如果要添加的时间内不会导致三重预订时,则可以存储这个新的日程安排。</p>
|
||||
|
||||
<p><code>MyCalendar</code> 有一个 <code>book(int start, int end)</code>方法。它意味着在 <code>start</code> 到 <code>end</code> 时间内增加一个日程安排,注意,这里的时间是半开区间,即 <code>[start, end)</code>, 实数 <code>x</code> 的范围为, <code>start <= x < end</code>。</p>
|
||||
<p>当三个日程安排有一些时间上的交叉时(例如三个日程安排都在同一时间内),就会产生 <strong>三重预订</strong>。</p>
|
||||
|
||||
<p>当三个日程安排有一些时间上的交叉时(例如三个日程安排都在同一时间内),就会产生三重预订。</p>
|
||||
<p>事件能够用一对整数 <code>startTime</code> 和 <code>endTime</code> 表示,在一个半开区间的时间 <code>[startTime, endTime)</code> 上预定。实数 <code>x</code> 的范围为 <code>startTime <= x < endTime</code>。</p>
|
||||
|
||||
<p>每次调用 <code>MyCalendar.book</code>方法时,如果可以将日程安排成功添加到日历中而不会导致三重预订,返回 <code>true</code>。否则,返回 <code>false</code> 并且不要将该日程安排添加到日历中。</p>
|
||||
<p>实现 <code>MyCalendarTwo</code> 类:</p>
|
||||
|
||||
<p>请按照以下步骤调用<code>MyCalendar</code> 类: <code>MyCalendar cal = new MyCalendar();</code> <code>MyCalendar.book(start, end)</code></p>
|
||||
<ul>
|
||||
<li><code>MyCalendarTwo()</code> 初始化日历对象。</li>
|
||||
<li><code>boolean book(int startTime, int endTime)</code> 如果可以将日程安排成功添加到日历中而不会导致三重预订,返回 <code>true</code>。否则,返回 <code>false</code> 并且不要将该日程安排添加到日历中。</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例:</strong></p>
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<pre>MyCalendar();
|
||||
MyCalendar.book(10, 20); // returns true
|
||||
MyCalendar.book(50, 60); // returns true
|
||||
MyCalendar.book(10, 40); // returns true
|
||||
MyCalendar.book(5, 15); // returns false
|
||||
MyCalendar.book(5, 10); // returns true
|
||||
MyCalendar.book(25, 55); // returns true
|
||||
<strong>解释:</strong>
|
||||
前两个日程安排可以添加至日历中。 第三个日程安排会导致双重预订,但可以添加至日历中。
|
||||
第四个日程安排活动(5,15)不能添加至日历中,因为它会导致三重预订。
|
||||
第五个日程安排(5,10)可以添加至日历中,因为它未使用已经双重预订的时间10。
|
||||
第六个日程安排(25,55)可以添加至日历中,因为时间 [25,40] 将和第三个日程安排双重预订;
|
||||
时间 [40,50] 将单独预订,时间 [50,55)将和第二个日程安排双重预订。
|
||||
<pre>
|
||||
<strong>输入:</strong>
|
||||
["MyCalendarTwo", "book", "book", "book", "book", "book", "book"]
|
||||
[[], [10, 20], [50, 60], [10, 40], [5, 15], [5, 10], [25, 55]]
|
||||
<strong>输出:</strong>
|
||||
[null, true, true, true, false, true, true]
|
||||
|
||||
<strong>解释:</strong>
|
||||
MyCalendarTwo myCalendarTwo = new MyCalendarTwo();
|
||||
myCalendarTwo.book(10, 20); // 返回 True,能够预定该日程。
|
||||
myCalendarTwo.book(50, 60); // 返回 True,能够预定该日程。
|
||||
myCalendarTwo.book(10, 40); // 返回 True,该日程能够被重复预定。
|
||||
myCalendarTwo.book(5, 15); // 返回 False,该日程导致了三重预定,所以不能预定。
|
||||
myCalendarTwo.book(5, 10); // 返回 True,能够预定该日程,因为它不使用已经双重预订的时间 10。
|
||||
myCalendarTwo.book(25, 55); // 返回 True,能够预定该日程,因为时间段 [25, 40) 将被第三个日程重复预定,时间段 [40, 50) 将被单独预定,而时间段 [50, 55) 将被第二个日程重复预定。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
@@ -32,6 +37,6 @@ MyCalendar.book(25, 55); // returns true
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>每个测试用例,调用 <code>MyCalendar.book</code> 函数最多不超过 <code>1000</code>次。</li>
|
||||
<li>调用函数 <code>MyCalendar.book(start, end)</code>时, <code>start</code> 和 <code>end</code> 的取值范围为 <code>[0, 10^9]</code>。</li>
|
||||
<li><code>0 <= start < end <= 10<sup>9</sup></code></li>
|
||||
<li>最多调用 <code>book</code> 1000 次。</li>
|
||||
</ul>
|
||||
|
Reference in New Issue
Block a user