[leetcode] 146. LRU Cache
来源:互联网 发布:自动竞价软件 编辑:程序博客网 时间:2024/06/14 03:24
- https://leetcode.com/problems/lru-cache/description/
class LRUCache {private: int _capacity; list<pair<int, int> > _list; unordered_map<int, list<pair<int, int> >::iterator> _map;public: LRUCache(int capacity) : _capacity(capacity) { } int get(int key) { auto it = _map.find(key); if (it == _map.end()) return -1; _list.splice(_list.begin(), _list, it->second); return it->second->second; } void put(int key, int value) { auto it = _map.find(key); if (it != _map.end()) { _list.splice(_list.begin(), _list, it->second); it->second->second = value; return ; } if (_map.size() == _capacity) { int del = _list.back().first; _list.pop_back(); _map.erase(del); } _list.emplace_front(key, value); _map[key] = _list.begin(); }};/** * Your LRUCache object will be instantiated and called as such: * LRUCache obj = new LRUCache(capacity); * int param_1 = obj.get(key); * obj.put(key,value); */
阅读全文
0 0
- LeetCode 146. LRU Cache
- [leetcode] 146.LRU Cache
- leetcode 146. LRU Cache
- Leetcode 146. LRU Cache
- Leetcode - 146. LRU Cache
- Leetcode 146. LRU Cache
- [leetcode] 146. LRU Cache
- Leetcode 146. LRU Cache
- leetcode 146. LRU Cache
- LeetCode-146. LRU Cache
- LeetCode 146. LRU Cache
- LeetCode 146. LRU Cache
- Leetcode 146. LRU Cache
- [LeetCode] 146. LRU Cache
- leetcode 146.LRU Cache
- [LeetCode]146. LRU Cache
- Leetcode 146. LRU Cache
- leetcode 146. LRU Cache
- gitflow工作流http://blog.jobbole.com/76867/
- 【22】手动配置webpack项目
- 协程
- 数据库加密
- 文章标题 判断单链表是否有环
- [leetcode] 146. LRU Cache
- 原生JavaScript写AJAX
- spring-boot 简介
- Java语法糖
- subline Text3 在写Python代码的时候 出现一些白色框
- 小游戏1024纯C语言
- 代码质量管理 阿里Java插件 + Upsource
- Apache模块加载流程
- Android学习记录20171023--Volley网络框架(一)