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 ...
随机推荐
- SVN菜单说明
01.SVN Checkout(SVN取出) 点击SVN Checkout,弹出检出提示框,在URL of repository输入框中输入服务器仓库地址,在Checkout directory输入框 ...
- python引入导入自定义模块和外部文件
参考:http://blog.csdn.net/devil_2009/article/details/15816237 项目中想使用以前的代码,或者什么样的需求致使你需要导入外部的包 如果是web 下 ...
- Oracle的rowid结构解析
SQL> select rowid,deptno from dept; ROWID DEPTNO ------------------ ---------- A ...
- jersey post提交到 ContainerRequestFilter 而HttpServletRequest获取不到数据(转)
jersey post提交到 ContainerRequestFilter 而HttpServletRequest获取不到数据 问题:在serverfilter request获取不到post提交的 ...
- linux运维面试题
一.有文件file1 1.查询file1 里面空行的所在行号 grep -n "^#" file1 or awk ‗{if($0~/^$/)print NR}‘ file or g ...
- WebKit Web Inspector增加覆盖率分析和类型推断功能
WebKit中的Web Inspector(Web检查器)主要用于查看页面源代码.实时DOM层次结构.脚本调试.数据收集等,日前增加了两个十分有用的新功能:覆盖率分析和类型推断.覆盖率分析工具能够可视 ...
- Java集合框架的知识总结(1)
说明:先从整体介绍了Java集合框架包含的接口和类,然后总结了集合框架中的一些基本知识和关键点,并结合实例进行简单分析. 1.综述 所有集合类都位于java.util包下.集合中只能保存对象(保存对象 ...
- 网页中插入Flvplayer视频播放器代码
http://blog.csdn.net/china_skag/article/details/7424019 原地址:http://yuweiqiang.blog.163.com/blog/stat ...
- jar包中的类如何读取包内和包外的配置文件
最近将代码打包成jar包,关于如何处理读取配置文件的问题特此记录一下. out.properties a.jar -com -a.class -in.properties 如上所示,out.prope ...
- 汇编中,BP,SP有何区别?分别怎么使用?
bp寄存器,跟其它什么BX,AX一样的用法, SP是用在栈上的,配合SS使用,像SS:SP SS上放段地址,SP上放偏移地址. 寻址时,像[bp],相当于SS:[bp] 就是说它默认使用SS 像BX默 ...