mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 15:31:43 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>一个观光景点由它的名字 <code>name</code> 和景点评分 <code>score</code> 组成,其中 <code>name</code> 是所有观光景点中 <strong>唯一</strong> 的字符串,<code>score</code> 是一个整数。景点按照最好到最坏排序。景点评分 <strong>越高</strong> ,这个景点越好。如果有两个景点的评分一样,那么 <strong>字典序较小</strong> 的景点更好。</p>\n\n<p>你需要搭建一个系统,查询景点的排名。初始时系统里没有任何景点。这个系统支持:</p>\n\n<ul>\n\t<li><strong>添加</strong> 景点,每次添加 <strong>一个</strong> 景点。</li>\n\t<li><strong>查询 </strong>已经添加景点中第 <code>i</code> <strong>好</strong> 的景点,其中 <code>i</code> 是系统目前位置查询的次数(包括当前这一次)。\n\t<ul>\n\t\t<li>比方说,如果系统正在进行第 <code>4</code> 次查询,那么需要返回所有已经添加景点中第 <code>4</code> 好的。</li>\n\t</ul>\n\t</li>\n</ul>\n\n<p>注意,测试数据保证 <strong>任意查询时刻</strong> ,查询次数都 <strong>不超过</strong> 系统中景点的数目。</p>\n\n<p>请你实现 <code>SORTracker</code> 类:</p>\n\n<ul>\n\t<li><code>SORTracker()</code> 初始化系统。</li>\n\t<li><code>void add(string name, int score)</code> 向系统中添加一个名为 <code>name</code> 评分为 <code>score</code> 的景点。</li>\n\t<li><code>string get()</code> 查询第 <code>i</code> 好的景点,其中 <code>i</code> 是目前系统查询的次数(包括当前这次查询)。</li>\n</ul>\n\n<p> </p>\n\n<p><strong>示例:</strong></p>\n\n<pre>\n<strong>输入:</strong>\n[\"SORTracker\", \"add\", \"add\", \"get\", \"add\", \"get\", \"add\", \"get\", \"add\", \"get\", \"add\", \"get\", \"get\"]\n[[], [\"bradford\", 2], [\"branford\", 3], [], [\"alps\", 2], [], [\"orland\", 2], [], [\"orlando\", 3], [], [\"alpine\", 2], [], []]\n<strong>输出:</strong>\n[null, null, null, \"branford\", null, \"alps\", null, \"bradford\", null, \"bradford\", null, \"bradford\", \"orland\"]\n\n<strong>解释:</strong>\nSORTracker tracker = new SORTracker(); // 初始化系统\ntracker.add(\"bradford\", 2); // 添加 name=\"bradford\" 且 score=2 的景点。\ntracker.add(\"branford\", 3); // 添加 name=\"branford\" 且 score=3 的景点。\ntracker.get(); // 从好带坏的景点为:branford ,bradford 。\n // 注意到 branford 比 bradford 好,因为它的 <strong>评分更高</strong> (3 > 2) 。\n // 这是第 1 次调用 get() ,所以返回最好的景点:\"branford\" 。\ntracker.add(\"alps\", 2); // 添加 name=\"alps\" 且 score=2 的景点。\ntracker.get(); // 从好到坏的景点为:branford, alps, bradford 。\n // 注意 alps 比 bradford 好,虽然它们评分相同,都为 2 。\n // 这是因为 \"alps\" <strong>字典序</strong> 比 \"bradford\" 小。\n // 返回第 2 好的地点 \"alps\" ,因为当前为第 2 次调用 get() 。\ntracker.add(\"orland\", 2); // 添加 name=\"orland\" 且 score=2 的景点。\ntracker.get(); // 从好到坏的景点为:branford, alps, bradford, orland 。\n // 返回 \"bradford\" ,因为当前为第 3 次调用 get() 。\ntracker.add(\"orlando\", 3); // 添加 name=\"orlando\" 且 score=3 的景点。\ntracker.get(); // 从好到坏的景点为:branford, orlando, alps, bradford, orland 。\n // 返回 \"bradford\".\ntracker.add(\"alpine\", 2); // 添加 name=\"alpine\" 且 score=2 的景点。\ntracker.get(); // 从好到坏的景点为:branford, orlando, alpine, alps, bradford, orland 。\n // 返回 \"bradford\" 。\ntracker.get(); // 从好到坏的景点为:branford, orlando, alpine, alps, bradford, orland 。\n // 返回 \"orland\" 。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>name</code> 只包含小写英文字母,且每个景点名字互不相同。</li>\n\t<li><code>1 <= name.length <= 10</code></li>\n\t<li><code>1 <= score <= 10<sup>5</sup></code></li>\n\t<li>任意时刻,调用 <code>get</code> 的次数都不超过调用 <code>add</code> 的次数。</li>\n\t<li><strong>总共</strong> 调用 <code>add</code> 和 <code>get</code> 不超过 <code>4 * 10<sup>4</sup></code> </li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Hard",
|
||||
"likes": 20,
|
||||
"likes": 22,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -155,7 +155,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"2.1K\", \"totalSubmission\": \"3.9K\", \"totalAcceptedRaw\": 2117, \"totalSubmissionRaw\": 3928, \"acRate\": \"53.9%\"}",
|
||||
"stats": "{\"totalAccepted\": \"2.2K\", \"totalSubmission\": \"4.1K\", \"totalAcceptedRaw\": 2221, \"totalSubmissionRaw\": 4140, \"acRate\": \"53.6%\"}",
|
||||
"hints": [
|
||||
"If the problem were to find the median of a stream of scenery locations while they are being added, can you solve it?",
|
||||
"We can use a similar approach as an optimization to avoid repeated sorting.",
|
||||
|
Reference in New Issue
Block a user