mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-02 22:13:28 +08:00
update
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"translatedContent": "<p>实现<code>RandomizedSet</code> 类:</p>\n\n<div class=\"original__bRMd\">\n<div>\n<ul>\n\t<li><code>RandomizedSet()</code> 初始化 <code>RandomizedSet</code> 对象</li>\n\t<li><code>bool insert(int val)</code> 当元素 <code>val</code> 不存在时,向集合中插入该项,并返回 <code>true</code> ;否则,返回 <code>false</code> 。</li>\n\t<li><code>bool remove(int val)</code> 当元素 <code>val</code> 存在时,从集合中移除该项,并返回 <code>true</code> ;否则,返回 <code>false</code> 。</li>\n\t<li><code>int getRandom()</code> 随机返回现有集合中的一项(测试用例保证调用此方法时集合中至少存在一个元素)。每个元素应该有 <strong>相同的概率</strong> 被返回。</li>\n</ul>\n\n<p>你必须实现类的所有函数,并满足每个函数的 <strong>平均</strong> 时间复杂度为 <code>O(1)</code> 。</p>\n\n<p> </p>\n\n<p><strong>示例:</strong></p>\n\n<pre>\n<strong>输入</strong>\n[\"RandomizedSet\", \"insert\", \"remove\", \"insert\", \"getRandom\", \"remove\", \"insert\", \"getRandom\"]\n[[], [1], [2], [2], [], [1], [2], []]\n<strong>输出</strong>\n[null, true, false, true, 2, true, false, 2]\n\n<strong>解释</strong>\nRandomizedSet randomizedSet = new RandomizedSet();\nrandomizedSet.insert(1); // 向集合中插入 1 。返回 true 表示 1 被成功地插入。\nrandomizedSet.remove(2); // 返回 false ,表示集合中不存在 2 。\nrandomizedSet.insert(2); // 向集合中插入 2 。返回 true 。集合现在包含 [1,2] 。\nrandomizedSet.getRandom(); // getRandom 应随机返回 1 或 2 。\nrandomizedSet.remove(1); // 从集合中移除 1 ,返回 true 。集合现在包含 [2] 。\nrandomizedSet.insert(2); // 2 已在集合中,所以返回 false 。\nrandomizedSet.getRandom(); // 由于 2 是集合中唯一的数字,getRandom 总是返回 2 。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>-2<sup>31</sup> <= val <= 2<sup>31</sup> - 1</code></li>\n\t<li>最多调用 <code>insert</code>、<code>remove</code> 和 <code>getRandom</code> 函数 <code>2 * </code><code>10<sup>5</sup></code> 次</li>\n\t<li>在调用 <code>getRandom</code> 方法时,数据结构中 <strong>至少存在一个</strong> 元素。</li>\n</ul>\n</div>\n</div>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Medium",
|
||||
"likes": 448,
|
||||
"likes": 544,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[{\"title\": \"Insert Delete GetRandom O(1) - Duplicates allowed\", \"titleSlug\": \"insert-delete-getrandom-o1-duplicates-allowed\", \"difficulty\": \"Hard\", \"translatedTitle\": \"O(1) \\u65f6\\u95f4\\u63d2\\u5165\\u3001\\u5220\\u9664\\u548c\\u83b7\\u53d6\\u968f\\u673a\\u5143\\u7d20 - \\u5141\\u8bb8\\u91cd\\u590d\"}]",
|
||||
@@ -161,7 +161,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"46.4K\", \"totalSubmission\": \"91.5K\", \"totalAcceptedRaw\": 46411, \"totalSubmissionRaw\": 91509, \"acRate\": \"50.7%\"}",
|
||||
"stats": "{\"totalAccepted\": \"77.5K\", \"totalSubmission\": \"146.6K\", \"totalAcceptedRaw\": 77482, \"totalSubmissionRaw\": 146552, \"acRate\": \"52.9%\"}",
|
||||
"hints": [],
|
||||
"solution": null,
|
||||
"status": null,
|
||||
|
Reference in New Issue
Block a user