lru cache java
http://www.acmerblog.com/leetcode-lru-cache-lru-5745.html
acm之家的讲解是在是好,丰富
import java.util.LinkedHashMap;
public class LRUCache {
private int capacity;
private LinkedHashMap<Integer,Integer> map=null; public LRUCache(int capacity) {
this.capacity=capacity;
map=new LinkedHashMap<Integer,Integer>(16,0.75f,true){
protected boolean removeEldestEntry(java.util.Map.Entry<Integer,Integer> eldest) { return size()>LRUCache.this.capacity; } };
} public int get(int key) {
if(map.get(key)==null)
{
return -1;
}
return map.get(key); } public void set(int key, int value) {
map.put(key,value); }
}
lru cache java的更多相关文章
- LeetCode – LRU Cache (Java)
Problem Design and implement a data structure for Least Recently Used (LRU) cache. It should support ...
- leetcode 146. LRU Cache ----- java
esign and implement a data structure for Least Recently Used (LRU) cache. It should support the foll ...
- LRU Cache java实现
要求: get(key):如果key在cache中,则返回对应的value值,否则返回null set(key,value):如果key不在cache中,则将该(key,value)插入cache中( ...
- Java for LeetCode 146 LRU Cache 【HARD】
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the fol ...
- LRU Cache leetcode java
题目: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the ...
- java基于Hash表和双向链表简单实现LRU Cache
package lru; import java.util.HashMap; public class LRUCache2<K,V> { public final int capacity ...
- LeetCode——LRU Cache
Description: Design and implement a data structure for Least Recently Used (LRU) cache. It should su ...
- LeetCode之LRU Cache 最近最少使用算法 缓存设计
设计并实现最近最久未使用(Least Recently Used)缓存. 题目描述: Design and implement a data structure for Least Recently ...
- 146. LRU Cache
题目: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the ...
随机推荐
- “微信应用号对行业影响”之一,app开发速来围观
昨天,微信张小龙的一个讲话刷爆朋友圈,除了4大价值观,最后顺便提到:要推出微信应用号! 其实,价值观也就说说听听,最后顺便提到的微信应用号,才是真正的巨型炸弹. 腾讯挟6亿高粘度用户之重,号令天下,阿 ...
- struts2处理.do后缀的请求
默认情况下,struts2是无法处理以.do为后缀的请求url的(默认情况下是.action或者不填,可以参见org.apache.struts2包下的default.properties文件). 但 ...
- Python设计模式——模版方法模式
1.模版方法模式 做题的列子: 需求:有两个学生,要回答问题,写出自己的答案 #encoding=utf-8 __author__ = 'kevinlu1010@qq.com' class Stude ...
- WPF 数据绑定Bingding基础(第四天)
程序的本质是数据加算法.数据会在存储.逻辑和展示三个层面沟通,在WPF中,展示层和逻辑层的沟通就使用Data Bingding来实现. Binding即“绑定”,如果把Bingding比作数据的桥梁, ...
- WebLogic启动时报错
java.lang.ClassCastException: com.octetstring.vde.backend.BackendRoot cannot be cast to com.octetstr ...
- 一步步学习ASP.NET MVC3 (1)——基础知识
请注明转载地址:http://www.cnblogs.com/arhat 首先在这里我想声明一下,这个ASP.NET MVC3系列是我在授课过程中的一些经验,有什么不对的地方,请大家指出,我们共同的学 ...
- 粗略阅读《Agile Software Development》后的感想
大致配合翻译和词典阅读了一下这篇文章之后,我另外还查阅了维基百科.百度百科和MBA智库百科还有一些网络上的文章.对敏捷开发有了一个大致上的浅显的认识. 敏捷建模(Agile Modeling,AM)的 ...
- 关于怎样拆毁Cuttheprice
最近我的chrome浏览器被一个叫cuttheprice的插件病毒感染了,总是弹出广告,真是让人抓狂,本来最近几天在复习算法,准备面试的,昨天忍了过去,今天实在受不了了,于是就干掉它吧.说干就干,刚开 ...
- Matlab 文件命名规则
Matlab 文件命名规则 1.文件名命名要用英文字符,第一个字符不能是数字和下划线. 2.文件名不要取为matlab的一个固有函数,m文件名的命名尽量不要是简单的英文单词,最好是由大小写英文.数字. ...
- static和const
转自说出static和const关键字尽可能多的作用 static关键字至少有下列n个作用: 函数体内static变量的作用范围为该函数体,不同于auto变量,该变量的内存只被分配一次,因此其值在下次 ...