Lintcode24 LFU Cache solution 题解
来源:互联网 发布:网络舆情信息 编辑:程序博客网 时间:2024/05/22 12:07
【题目描述】
LFU (Least Frequently Used) is a famous cache eviction algorithm.For a cache with capacity k, if the cache is full and need to evict a key in it, the key with the lease frequently used will be kicked out.Implement set and get method for LFU cache.
LFU是一个著名的缓存算法。实现LFU中的set 和 get
【题目链接】
http://www.lintcode.com/en/problem/lfu-cache/
【题目解析】
这道题让我们实现一个LRU缓存器,LRU是Least Recently Used的简写,就是最近最少使用的意思。那么这个缓存器主要有两个成员函数,get和set,其中get函数是通过输入key来获得value,如果成功获得后,这对(key, value)升至缓存器中最常用的位置(顶部),如果key不存在,则返回-1。而set函数是插入一对新的(key, value),如果原缓存器中有该key,则需要先删除掉原有的,将新的插入到缓存器的顶部。如果不存在,则直接插入到顶部。若加入新的值后缓存器超过了容量,则需要删掉一个最不常用的值,也就是底部的值。具体实现时我们需要三个私有变量,cap, l和m,其中cap是缓存器的容量大小,l是保存缓存器内容的列表,m是哈希表,保存关键值key和缓存器各项的迭代器之间映射,方便我们以O(1)的时间内找到目标项。
【参考答案】
http://www.jiuzhang.com/solutions/lfu-cache/
- Lintcode24 LFU Cache solution 题解
- Lintcode134 Lru Cache solution 题解
- LFU Cache
- LFU Cache
- LFU cache Java
- 460LFU Cache
- LeetCode 460. LFU Cache
- LeetCode 460. LFU Cache
- 460. LFU Cache
- 460. LFU Cache
- [LeetCode]460. LFU Cache
- Leetcode 460. LFU Cache
- [LeetCode] LFU Cache
- Leetcode 460. LFU Cache
- leetcode 460. LFU Cache
- LeetCode 460. LFU Cache
- 460. LFU Cache
- 20170604-leetcode-460-LFU Cache
- Java多线程(四)之——Lock
- Rational Grading UVALive
- POJ 1035
- Leetcode 278. First Bad Version
- 自考之路—操作系统阶段小结2
- Lintcode24 LFU Cache solution 题解
- 通过SharePreferences 记住密码
- ZOJ
- HTML
- CentOS下的Hadoop安装教程
- Android Studio logcat 设置 缓存大小 ,增加logcat条数
- 二叉树的前序遍历
- hdu 1004 让气球飞 (map)
- Idea使用技巧