mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-12 10:51:42 +08:00
批量更新数据
This commit is contained in:
@@ -1,23 +1,35 @@
|
||||
<p>在考场里,一排有 <code>N</code> 个座位,分别编号为 <code>0, 1, 2, ..., N-1</code> 。</p>
|
||||
<p>在考场里,有 <code>n</code> 个座位排成一行,编号为 <code>0</code> 到 <code>n - 1</code>。</p>
|
||||
|
||||
<p>当学生进入考场后,他必须坐在能够使他与离他最近的人之间的距离达到最大化的座位上。如果有多个这样的座位,他会坐在编号最小的座位上。(另外,如果考场里没有人,那么学生就坐在 0 号座位上。)</p>
|
||||
<p>当学生进入考场后,他必须坐在离最近的人最远的座位上。如果有多个这样的座位,他会坐在编号最小的座位上。(另外,如果考场里没有人,那么学生就坐在 <code>0</code> 号座位上。)</p>
|
||||
|
||||
<p>返回 <code>ExamRoom(int N)</code> 类,它有两个公开的函数:其中,函数 <code>ExamRoom.seat()</code> 会返回一个 <code>int</code> (整型数据),代表学生坐的位置;函数 <code>ExamRoom.leave(int p)</code> 代表坐在座位 <code>p</code> 上的学生现在离开了考场。每次调用 <code>ExamRoom.leave(p)</code> 时都保证有学生坐在座位 <code>p</code> 上。</p>
|
||||
<p>设计一个模拟所述考场的类。</p>
|
||||
|
||||
<p>实现 <code>ExamRoom</code> 类:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>ExamRoom(int n)</code> 用座位的数量 <code>n</code> 初始化考场对象。</li>
|
||||
<li><code>int seat()</code> 返回下一个学生将会入座的座位编号。</li>
|
||||
<li><code>void leave(int p)</code> 指定坐在座位 <code>p</code> 的学生将离开教室。保证座位 <code>p</code> 上会有一位学生。</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例:</strong></p>
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong>["ExamRoom","seat","seat","seat","seat","leave","seat"], [[10],[],[],[],[],[4],[]]
|
||||
<strong>输出:</strong>[null,0,9,4,2,null,5]
|
||||
<pre>
|
||||
<strong>输入:</strong>
|
||||
["ExamRoom", "seat", "seat", "seat", "seat", "leave", "seat"]
|
||||
[[10], [], [], [], [], [4], []]
|
||||
<strong>输出:</strong>
|
||||
[null, 0, 9, 4, 2, null, 5]
|
||||
<strong>解释:</strong>
|
||||
ExamRoom(10) -> null
|
||||
seat() -> 0,没有人在考场里,那么学生坐在 0 号座位上。
|
||||
seat() -> 9,学生最后坐在 9 号座位上。
|
||||
seat() -> 4,学生最后坐在 4 号座位上。
|
||||
seat() -> 2,学生最后坐在 2 号座位上。
|
||||
leave(4) -> null
|
||||
seat() -> 5,学生最后坐在 5 号座位上。
|
||||
ExamRoom examRoom = new ExamRoom(10);
|
||||
examRoom.seat(); // 返回 0,房间里没有人,学生坐在 0 号座位。
|
||||
examRoom.seat(); // 返回 9,学生最后坐在 9 号座位。
|
||||
examRoom.seat(); // 返回 4,学生最后坐在 4 号座位。
|
||||
examRoom.seat(); // 返回 2,学生最后坐在 2 号座位。
|
||||
examRoom.leave(4);
|
||||
examRoom.seat(); // 返回 5,学生最后坐在 5 号座位。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
@@ -25,7 +37,7 @@ seat() -> 5,学生最后坐在 5 号座位上。
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ol>
|
||||
<li><code>1 <= N <= 10^9</code></li>
|
||||
<li>在所有的测试样例中 <code>ExamRoom.seat()</code> 和 <code>ExamRoom.leave()</code> 最多被调用 <code>10^4</code> 次。</li>
|
||||
<li>保证在调用 <code>ExamRoom.leave(p)</code> 时有学生正坐在座位 <code>p</code> 上。</li>
|
||||
<li><code>1 <= n <= 10<sup>9</sup></code></li>
|
||||
<li>保证有学生正坐在座位 <code>p</code> 上。</li>
|
||||
<li><code>seat</code> 和 <code>leave</code> 最多被调用 <code>10<sup>4</sup></code> 次。</li>
|
||||
</ol>
|
||||
|
Reference in New Issue
Block a user