Title: leetcode380:常数时间插入、删除和获取随机元素 · Issue #48 · sisterAn/JavaScript-Algorithms · GitHub
Open Graph Title: leetcode380:常数时间插入、删除和获取随机元素 · Issue #48 · sisterAn/JavaScript-Algorithms
X Title: leetcode380:常数时间插入、删除和获取随机元素 · Issue #48 · sisterAn/JavaScript-Algorithms
Description: 设计一个支持在平均 时间复杂度 O(1) 下,执行以下操作的数据结构。 insert(val) :当元素 val 不存在时,向集合中插入该项。 remove(val) :元素 val 存在时,从集合中移除该项。 getRandom :随机返回现有集合中的一项。每个元素应该有 相同的概率 被返回。 示例 : // 初始化一个空的集合。 RandomizedSet randomSet = new RandomizedSet(); // 向集合中插入 1 。返回 true 表...
Open Graph Description: 设计一个支持在平均 时间复杂度 O(1) 下,执行以下操作的数据结构。 insert(val) :当元素 val 不存在时,向集合中插入该项。 remove(val) :元素 val 存在时,从集合中移除该项。 getRandom :随机返回现有集合中的一项。每个元素应该有 相同的概率 被返回。 示例 : // 初始化一个空的集合。 RandomizedSet randomSet = new...
X Description: 设计一个支持在平均 时间复杂度 O(1) 下,执行以下操作的数据结构。 insert(val) :当元素 val 不存在时,向集合中插入该项。 remove(val) :元素 val 存在时,从集合中移除该项。 getRandom :随机返回现有集合中的一项。每个元素应该有 相同的概率 被返回。 示例 : // 初始化一个空的集合。 RandomizedSet randomSet = new...
Opengraph URL: https://github.com/sisterAn/JavaScript-Algorithms/issues/48
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"leetcode380:常数时间插入、删除和获取随机元素","articleBody":"设计一个支持在平均 时间复杂度 **O(1)** 下,执行以下操作的数据结构。\r\n\r\n- `insert(val)` :当元素 val 不存在时,向集合中插入该项。\r\n- `remove(val)` :元素 val 存在时,从集合中移除该项。\r\n- `getRandom` :随机返回现有集合中的一项。每个元素应该有 **相同的概率** 被返回。\r\n\r\n**示例 :**\r\n\r\n```js\r\n// 初始化一个空的集合。\r\nRandomizedSet randomSet = new RandomizedSet();\r\n\r\n// 向集合中插入 1 。返回 true 表示 1 被成功地插入。\r\nrandomSet.insert(1);\r\n\r\n// 返回 false ,表示集合中不存在 2 。\r\nrandomSet.remove(2);\r\n\r\n// 向集合中插入 2 。返回 true 。集合现在包含 [1,2] 。\r\nrandomSet.insert(2);\r\n\r\n// getRandom 应随机返回 1 或 2 。\r\nrandomSet.getRandom();\r\n\r\n// 从集合中移除 1 ,返回 true 。集合现在包含 [2] 。\r\nrandomSet.remove(1);\r\n\r\n// 2 已在集合中,所以返回 false 。\r\nrandomSet.insert(2);\r\n\r\n// 由于 2 是集合中唯一的数字,getRandom 总是返回 2 。\r\nrandomSet.getRandom();\r\n```\r\n附赠leetcode地址:[leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1/solution/javascriptchang-shu-shi-jian-cha-ru-shan-chu-he-hu/)","author":{"url":"https://github.com/sisterAn","@type":"Person","name":"sisterAn"},"datePublished":"2020-05-24T14:37:41.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":12},"url":"https://github.com/48/JavaScript-Algorithms/issues/48"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:2b9acaac-cbc5-d5fc-2698-01ea2d8eb938 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9558:992B3:E0BEB4:13A4AB1:696A6879 |
| html-safe-nonce | 4becfe1ebb938e7aeb9ef24acc0a9353dcb868701f269893e93f6ecf8d987db6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NTU4Ojk5MkIzOkUwQkVCNDoxM0E0QUIxOjY5NkE2ODc5IiwidmlzaXRvcl9pZCI6Ijc5MTI1ODQyNDc5MzMyOTg4MDkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 968200ec8019f1494e2b30147d0606a8889795bf7f23ceb3118ea6c85e5f9707 |
| hovercard-subject-tag | issue:623877444 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/sisterAn/JavaScript-Algorithms/48/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b17c8f8e5ee736b5bf21aef2d42b43aa4b8fd11b4ef287ad0e7753138738d425/sisterAn/JavaScript-Algorithms/issues/48 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b17c8f8e5ee736b5bf21aef2d42b43aa4b8fd11b4ef287ad0e7753138738d425/sisterAn/JavaScript-Algorithms/issues/48 |
| og:image:alt | 设计一个支持在平均 时间复杂度 O(1) 下,执行以下操作的数据结构。 insert(val) :当元素 val 不存在时,向集合中插入该项。 remove(val) :元素 val 存在时,从集合中移除该项。 getRandom :随机返回现有集合中的一项。每个元素应该有 相同的概率 被返回。 示例 : // 初始化一个空的集合。 RandomizedSet randomSet = new... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sisterAn |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6fea32d5b7276b841b7a803796d9715bc6cfb31ed549fdf9de2948ac25d12ba6 |
| turbo-cache-control | no-preview |
| go-import | github.com/sisterAn/JavaScript-Algorithms git https://github.com/sisterAn/JavaScript-Algorithms.git |
| octolytics-dimension-user_id | 19721451 |
| octolytics-dimension-user_login | sisterAn |
| octolytics-dimension-repository_id | 252061924 |
| octolytics-dimension-repository_nwo | sisterAn/JavaScript-Algorithms |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 252061924 |
| octolytics-dimension-repository_network_root_nwo | sisterAn/JavaScript-Algorithms |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f2d9f6432a5a115ec709295ae70623f33bb80aee |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width