1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-05 07:21:40 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-05-02 23:44:12 +08:00
parent 7ea03594b3
commit 2a71c78585
4790 changed files with 11696 additions and 10944 deletions

View File

@@ -12,7 +12,7 @@
"translatedContent": "<p>请你设计一个管理 <code>n</code> 个座位预约的系统,座位编号从 <code>1</code> 到 <code>n</code> 。</p>\n\n<p>请你实现 <code>SeatManager</code> 类:</p>\n\n<ul>\n\t<li><code>SeatManager(int n)</code> 初始化一个 <code>SeatManager</code> 对象,它管理从 <code>1</code> 到 <code>n</code> 编号的 <code>n</code> 个座位。所有座位初始都是可预约的。</li>\n\t<li><code>int reserve()</code> 返回可以预约座位的 <strong>最小编号</strong> ,此座位变为不可预约。</li>\n\t<li><code>void unreserve(int seatNumber)</code> 将给定编号 <code>seatNumber</code> 对应的座位变成可以预约。</li>\n</ul>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n\n<pre><strong>输入:</strong>\n[\"SeatManager\", \"reserve\", \"reserve\", \"unreserve\", \"reserve\", \"reserve\", \"reserve\", \"reserve\", \"unreserve\"]\n[[5], [], [], [2], [], [], [], [], [5]]\n<strong>输出:</strong>\n[null, 1, 2, null, 2, 3, 4, 5, null]\n\n<strong>解释:</strong>\nSeatManager seatManager = new SeatManager(5); // 初始化 SeatManager ,有 5 个座位。\nseatManager.reserve(); // 所有座位都可以预约,所以返回最小编号的座位,也就是 1 。\nseatManager.reserve(); // 可以预约的座位为 [2,3,4,5] ,返回最小编号的座位,也就是 2 。\nseatManager.unreserve(2); // 将座位 2 变为可以预约,现在可预约的座位为 [2,3,4,5] 。\nseatManager.reserve(); // 可以预约的座位为 [2,3,4,5] ,返回最小编号的座位,也就是 2 。\nseatManager.reserve(); // 可以预约的座位为 [3,4,5] ,返回最小编号的座位,也就是 3 。\nseatManager.reserve(); // 可以预约的座位为 [4,5] ,返回最小编号的座位,也就是 4 。\nseatManager.reserve(); // 唯一可以预约的是座位 5 ,所以返回 5 。\nseatManager.unreserve(5); // 将座位 5 变为可以预约,现在可预约的座位为 [5] 。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>\n\t<li><code>1 &lt;= seatNumber &lt;= n</code></li>\n\t<li>每一次对 <code>reserve</code> 的调用,题目保证至少存在一个可以预约的座位。</li>\n\t<li>每一次对 <code>unreserve</code> 的调用,题目保证 <code>seatNumber</code> 在调用函数前都是被预约状态。</li>\n\t<li>对 <code>reserve</code> 和 <code>unreserve</code> 的调用 <strong>总共</strong> 不超过 <code>10<sup>5</sup></code> 次。</li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 11,
"likes": 12,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -143,7 +143,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"9.1K\", \"totalSubmission\": \"18.7K\", \"totalAcceptedRaw\": 9147, \"totalSubmissionRaw\": 18651, \"acRate\": \"49.0%\"}",
"stats": "{\"totalAccepted\": \"10K\", \"totalSubmission\": \"20.4K\", \"totalAcceptedRaw\": 9987, \"totalSubmissionRaw\": 20433, \"acRate\": \"48.9%\"}",
"hints": [
"You need a data structure that maintains the states of the seats. This data structure should also allow you to get the first available seat and flip the state of a seat in a reasonable time.",
"You can let the data structure contain the available seats. Then you want to be able to get the lowest element and erase an element, in a reasonable time.",