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 ...
随机推荐
- Spring 官方下载地址(非Maven)
现在spring的官网停止了使用zip包下载,只能使用maven,非常的不方便,分享如下网址可以使用zip包下载,是不是方便多了!~ 下载列表如下: spring-framework-3.2.8.RE ...
- php 中文字符串首字母的获取函数
这篇文章介绍了php 中文字符串首字母的获取函数,有需要的朋友可以参考一下 function chineseFirst($str) { $str= iconv("UTF-8",&q ...
- 【python】坑,坑,折腾一个下午python 3.5中 ImportError: No module named BeautifulSoup
将语句 from bs4 import BeautifulSoup4 改成 from bs4 import BeautifulSoup 通过 尼玛------------------------! 总 ...
- NSAssert使用摘抄
#define NSAssert(condition, desc, ...) 只有条件condition满足,才会执行下一个语句,否则输出断言错误. 例如: NSAssert(1 != 2, @&qu ...
- SpringMVC+Hibernate架构save方法事务未提交
今天同事遇到一个问题,一起研究,最后解决,让我对spring的事务管理又加深了印象. 先简单说一下项目:项目是Spring和Hibernate集成的JavaEE项目,MVC架构. 外包在service ...
- MSCRM4.0如何使js事件在批量编辑表单中触发
MSCRM4.0如何使js事件在批量编辑表单中触发 MSCRM4.0如何使js事件在批量编辑表单中触发 MSCRM3.0我们可以通过在onload事件加入以下代码来控制某个属性为只读.crmForm. ...
- ExtJS 获取浏览器宽度
JS中代码: Ext.onReady(function() { var width=window.screen.availWidth; var height=window.screen.availHe ...
- 【NOIP TG 解方程】
存代码: #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> ...
- NSMutableArray,NSMutableDictionary的内存管问题
今天做项目遇到一个问题,在一个类中定义了一个可变数组,使用的是copy的内存管理策略 当往数组中添加包装好的基本数据的时候,程序直接崩溃了.解决方法:把copy换成strong就不会崩溃了; 后来做了 ...
- codeforces Mafia
/* * Mafia.cpp * * Created on: 2013-10-12 * Author: wangzhu */ /** * 每个人都想玩若干场,求至少需要玩几场才可以满足大家的需求. * ...