1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-12-19 02:24:59 +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>设计一个支持在<em>平均&nbsp;</em>时间复杂度 <strong>O(1)</strong>&nbsp;下,执行以下操作的数据结构:</p>\n\n<ul>\n\t<li><code>insert(val)</code>:当元素 <code>val</code> 不存在时返回 <code>true</code>&nbsp;,并向集合中插入该项,否则返回 <code>false</code> 。</li>\n\t<li><code>remove(val)</code>:当元素 <code>val</code> 存在时返回 <code>true</code>&nbsp;,并从集合中移除该项,否则返回 <code>false</code>&nbsp;。</li>\n\t<li><code>getRandom</code>:随机返回现有集合中的一项。每个元素应该有&nbsp;<strong>相同的概率&nbsp;</strong>被返回。</li>\n</ul>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 :</strong></p>\n\n<pre>\n<strong>输入: </strong>inputs = [&quot;RandomizedSet&quot;, &quot;insert&quot;, &quot;remove&quot;, &quot;insert&quot;, &quot;getRandom&quot;, &quot;remove&quot;, &quot;insert&quot;, &quot;getRandom&quot;]\n[[], [1], [2], [2], [], [1], [2], []]\n<strong>输出: </strong>[null, true, false, true, 2, true, false, 2]\n<strong>解释:\n</strong>RandomizedSet randomSet = new RandomizedSet(); // 初始化一个空的集合\nrandomSet.insert(1); // 向集合中插入 1 返回 true 表示 1 被成功地插入\n\nrandomSet.remove(2); // 返回 false表示集合中不存在 2 \n\nrandomSet.insert(2); // 向集合中插入 2 返回 true ,集合现在包含 [1,2] \n\nrandomSet.getRandom(); // getRandom 应随机返回 1 或 2 \n \nrandomSet.remove(1); // 从集合中移除 1 返回 true 。集合现在包含 [2] \n\nrandomSet.insert(2); // 2 已在集合中,所以返回 false \n\nrandomSet.getRandom(); // 由于 2 是集合中唯一的数字getRandom 总是返回 2 \n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong><meta charset=\"UTF-8\" /></p>\n\n<ul>\n\t<li><code>-2<sup>31</sup>&nbsp;&lt;= val &lt;= 2<sup>31</sup>&nbsp;- 1</code></li>\n\t<li>最多进行<code> 2 * 10<sup>5</sup></code> 次&nbsp;<code>insert</code> <code>remove</code> 和 <code>getRandom</code> 方法调用</li>\n\t<li>当调用&nbsp;<code>getRandom</code> 方法时,集合中至少有一个元素</li>\n</ul>\n\n<p>&nbsp;</p>\n\n<p><meta charset=\"UTF-8\" />注意:本题与主站 380&nbsp;题相同:<a href=\"https://leetcode-cn.com/problems/insert-delete-getrandom-o1/\">https://leetcode-cn.com/problems/insert-delete-getrandom-o1/</a></p>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 24,
"likes": 31,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -168,7 +168,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"8.6K\", \"totalSubmission\": \"15.9K\", \"totalAcceptedRaw\": 8637, \"totalSubmissionRaw\": 15891, \"acRate\": \"54.4%\"}",
"stats": "{\"totalAccepted\": \"10.2K\", \"totalSubmission\": \"18.8K\", \"totalAcceptedRaw\": 10227, \"totalSubmissionRaw\": 18817, \"acRate\": \"54.3%\"}",
"hints": [],
"solution": null,
"status": null,