mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-12-19 02:24:59 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>设计一个支持在<em>平均 </em>时间复杂度 <strong>O(1)</strong> 下,执行以下操作的数据结构:</p>\n\n<ul>\n\t<li><code>insert(val)</code>:当元素 <code>val</code> 不存在时返回 <code>true</code> ,并向集合中插入该项,否则返回 <code>false</code> 。</li>\n\t<li><code>remove(val)</code>:当元素 <code>val</code> 存在时返回 <code>true</code> ,并从集合中移除该项,否则返回 <code>false</code> 。</li>\n\t<li><code>getRandom</code>:随机返回现有集合中的一项。每个元素应该有 <strong>相同的概率 </strong>被返回。</li>\n</ul>\n\n<p> </p>\n\n<p><strong>示例 :</strong></p>\n\n<pre>\n<strong>输入: </strong>inputs = ["RandomizedSet", "insert", "remove", "insert", "getRandom", "remove", "insert", "getRandom"]\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> </p>\n\n<p><strong>提示:</strong><meta charset=\"UTF-8\" /></p>\n\n<ul>\n\t<li><code>-2<sup>31</sup> <= val <= 2<sup>31</sup> - 1</code></li>\n\t<li>最多进行<code> 2 * 10<sup>5</sup></code> 次 <code>insert</code> , <code>remove</code> 和 <code>getRandom</code> 方法调用</li>\n\t<li>当调用 <code>getRandom</code> 方法时,集合中至少有一个元素</li>\n</ul>\n\n<p> </p>\n\n<p><meta charset=\"UTF-8\" />注意:本题与主站 380 题相同:<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,
|
||||
|
||||
Reference in New Issue
Block a user