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的更多相关文章

  1. LeetCode – LRU Cache (Java)

    Problem Design and implement a data structure for Least Recently Used (LRU) cache. It should support ...

  2. leetcode 146. LRU Cache ----- java

    esign and implement a data structure for Least Recently Used (LRU) cache. It should support the foll ...

  3. LRU Cache java实现

    要求: get(key):如果key在cache中,则返回对应的value值,否则返回null set(key,value):如果key不在cache中,则将该(key,value)插入cache中( ...

  4. Java for LeetCode 146 LRU Cache 【HARD】

    Design and implement a data structure for Least Recently Used (LRU) cache. It should support the fol ...

  5. LRU Cache leetcode java

    题目: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the ...

  6. java基于Hash表和双向链表简单实现LRU Cache

    package lru; import java.util.HashMap; public class LRUCache2<K,V> { public final int capacity ...

  7. LeetCode——LRU Cache

    Description: Design and implement a data structure for Least Recently Used (LRU) cache. It should su ...

  8. LeetCode之LRU Cache 最近最少使用算法 缓存设计

    设计并实现最近最久未使用(Least Recently Used)缓存. 题目描述: Design and implement a data structure for Least Recently ...

  9. 146. LRU Cache

    题目: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the ...

随机推荐

  1. normalize.css介绍

    Normalize.css 只是一个很小的CSS文件,但它在默认的HTML元素样式上提供了跨浏览器的高度一致性.相比于传统的CSS reset,Normalize.css是一种现代的.为HTML5准备 ...

  2. CentOS 根据命令查所在的包

    在工作中经常会遇到想用某个命令机器没装却又不知道命令在哪个包(源码编译不再本文范围内),下面介绍个比较笨的方法可以帮助我们搞定这个问题. 说明:蓝色=命令名称       浅绿=命令参数       ...

  3. 关于window.location不跳转的问题

    今天在码代码的时候遇到个问题:html里采用onclick事件来实现window.location = url的跳转,在内嵌元素上又加上了href="javascrit:;"的属性 ...

  4. 压力测试之apache benchmark

    ab 的全称是 ApacheBench , 是 Apache 附带的一个小工具 , 专门用于 HTTP Server 的 benchmark testing , 可以同时模拟多个并发请求.前段时间看到 ...

  5. WinForm小小应用

    制作日历计划任务 private void BeginTask() { Thread th = new Thread(//建立线程 (() =>//使用Lambda表达式 { while (tr ...

  6. EventLog组件

    1.使用EventLog组件读写事件日志 SourceExists方法  确定事件源是否已在本地计算机上注册 DeleteEventSource方法  用于从事件日志中移除应用程序的事件源注册 pri ...

  7. 【Catalina】

    Tomcat's servlet container was redesigned as Catalina in Tomcat version 4.x. The architect for Catal ...

  8. Pentaho Data Integration笔记 (四):Kitchen

    官方网站: http://wiki.pentaho.com/display/EAI/Kitchen+User+Documentation Kitchen Kitchen是一个可以执行Spoon编辑的J ...

  9. 用easyui动态创建一个对话框

    function randomString(len) { len = len || 32; var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxy ...

  10. quicksort+binarySearch

    描述 数轴上有n个点,对于任一闭区间 [a, b],试计算落在其内的点数. 输入 第一行包括两个整数:点的总数n,查询的次数m. 第二行包含n个数,为各个点的坐标. 以下m行,各包含两个整数:查询区间 ...