Title: 华为&leetcode146:LRU 缓存机制 · Issue #7 · sisterAn/JavaScript-Algorithms · GitHub
Open Graph Title: 华为&leetcode146:LRU 缓存机制 · Issue #7 · sisterAn/JavaScript-Algorithms
X Title: 华为&leetcode146:LRU 缓存机制 · Issue #7 · sisterAn/JavaScript-Algorithms
Description: 运用你所掌握的数据结构,设计和实现一个 LRU (最近最少使用) 缓存机制。它应该支持以下操作: 获取数据 get 和写入数据 put 。 获取数据 get(key) - 如果密钥 ( key ) 存在于缓存中,则获取密钥的值(总是正数),否则返回 -1 。 写入数据 put(key, value) - 如果密钥不存在,则写入数据。当缓存容量达到上限时,它应该在写入新数据之前删除最久未使用的数据,从而为新数据留出空间。 进阶: 你是否可以在 O(1) 时间复杂度内完成这...
Open Graph Description: 运用你所掌握的数据结构,设计和实现一个 LRU (最近最少使用) 缓存机制。它应该支持以下操作: 获取数据 get 和写入数据 put 。 获取数据 get(key) - 如果密钥 ( key ) 存在于缓存中,则获取密钥的值(总是正数),否则返回 -1 。 写入数据 put(key, value) - 如果密钥不存在,则写入数据。当缓存容量达到上限时,它应该在写入新数据之前删除最久未使用的...
X Description: 运用你所掌握的数据结构,设计和实现一个 LRU (最近最少使用) 缓存机制。它应该支持以下操作: 获取数据 get 和写入数据 put 。 获取数据 get(key) - 如果密钥 ( key ) 存在于缓存中,则获取密钥的值(总是正数),否则返回 -1 。 写入数据 put(key, value) - 如果密钥不存在,则写入数据。当缓存容量达到上限时,它应该在写入新数据之前删除最久未使用的...
Opengraph URL: https://github.com/sisterAn/JavaScript-Algorithms/issues/7
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"华为\u0026leetcode146:LRU 缓存机制","articleBody":"运用你所掌握的数据结构,设计和实现一个 LRU (最近最少使用) 缓存机制。它应该支持以下操作: 获取数据 `get` 和写入数据 `put` 。\r\n\r\n获取数据 `get(key)` - 如果密钥 ( `key` ) 存在于缓存中,则获取密钥的值(总是正数),否则返回 `-1` 。\r\n写入数据 `put(key, value)` - 如果密钥不存在,则写入数据。当缓存容量达到上限时,它应该在写入新数据之前删除最久未使用的数据,从而为新数据留出空间。\r\n\r\n**进阶:**\r\n\r\n你是否可以在 **O(1)** 时间复杂度内完成这两种操作?\r\n\r\n**示例:**\r\n\r\n```js\r\nLRUCache cache = new LRUCache( 2 /* 缓存容量 */ );\r\n\r\ncache.put(1, 1);\r\ncache.put(2, 2);\r\ncache.get(1); // 返回 1\r\ncache.put(3, 3); // 该操作会使得密钥 2 作废\r\ncache.get(2); // 返回 -1 (未找到)\r\ncache.put(4, 4); // 该操作会使得密钥 1 作废\r\ncache.get(1); // 返回 -1 (未找到)\r\ncache.get(3); // 返回 3\r\ncache.get(4); // 返回 4\r\n```\r\n附leetcode地址:[leetcode](https://leetcode-cn.com/problems/lru-cache/solution/ping-zi-jun-qian-duan-jin-jie-suan-fa-lru-shi-xian/)","author":{"url":"https://github.com/sisterAn","@type":"Person","name":"sisterAn"},"datePublished":"2020-04-06T12:50:15.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":23},"url":"https://github.com/7/JavaScript-Algorithms/issues/7"}
| 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:46b427b0-b56f-bae7-0db7-0e097ecd11d4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9680:992B3:DF64D5:13868BA:696A6842 |
| html-safe-nonce | 2683c58481d9cf992770c7b8d9e6ce8ed29bbb55523e70c6a19aa1e959a24bb9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NjgwOjk5MkIzOkRGNjRENToxMzg2OEJBOjY5NkE2ODQyIiwidmlzaXRvcl9pZCI6IjUyODcxMTA5NDA3ODIzODkzMTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2df4985044f49edabe4cf51231feff4fb62e72433f74af4479b81434a2c32379 |
| hovercard-subject-tag | issue:595088959 |
| 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/7/issue_layout |
| twitter:image | https://opengraph.githubassets.com/84ef35a9dceee4250df5e577b39267d49ff00da46568e4f0df58e3ff1a6d915c/sisterAn/JavaScript-Algorithms/issues/7 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/84ef35a9dceee4250df5e577b39267d49ff00da46568e4f0df58e3ff1a6d915c/sisterAn/JavaScript-Algorithms/issues/7 |
| og:image:alt | 运用你所掌握的数据结构,设计和实现一个 LRU (最近最少使用) 缓存机制。它应该支持以下操作: 获取数据 get 和写入数据 put 。 获取数据 get(key) - 如果密钥 ( key ) 存在于缓存中,则获取密钥的值(总是正数),否则返回 -1 。 写入数据 put(key, value) - 如果密钥不存在,则写入数据。当缓存容量达到上限时,它应该在写入新数据之前删除最久未使用的... |
| 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