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KAtV+vx+DgpoLygNV0lf+nN9tmvSVP6vRddOHqMMf1ZBSUspX/qR+E6gAAACAE1hJoDLfdr7sZsWE8f3CQOVuLH2dz22M80f8/I287y4KbT7UdmxcVQm/QLWXA5VWJoEKAAAAOLGVBCr1N5bMXyCy/tCd+1caNv6fTdcehdl/Nl15TmS0JeEvZlj/Etu891KXGHnGXGT/DUKpzIRAtfb/zzEAAABwWQsJVEtF4AAAAACgI1DZzO/g8T9sAgAAABBEoHJpX8gDAAAAAAeBCgAAAAAKEagAAAAAoBCBCgAAAAAKEagAAAAAoBCBCgAAAAAKEagAAAAAoBCBCgAAAAAKEagAAAAAoBCBCgAAAAAKEagAAAAAoBCBCgAAAAAKEagAAAAAoBCBCgAAAAAKEagAAAAAoBCBCgAAAAAKEagAAAAAoBCBCgAAAAAKEagAAAAAoBCBCgAAAAAKTQ1UAAAAAPDPIlABAAAAQCECFQAAAAAUIlABAAAAQKH/B9bfxRPF4gAzAAAAAElFTkSuQmCC" alt="" />
1 package leetcode; import java.util.HashMap;
import java.util.Map; class Node{
int key;
int value;
Node pre;
Node next;
Node(int key,int value){
this.key=key;
this.value=value;
this.pre=null;
this.next=null;
}
}
class CacheList{
private Node head;
private Node tail;
CacheList(int capacity){
head = new Node(0,0);
tail = new Node(0,0);
head.next=tail;
tail.pre=head;
}
public void insertFirst(Node n){
n.next=head.next;
head.next.pre=n;
head.next=n;
n.pre=head; }
public Node removeLast(){
Node re = tail.pre;
tail.pre.pre.next=tail;
tail.pre=tail.pre.pre;
return re;
}
public void shiftToFirst(Node n){
n.pre.next=n.next;
n.next.pre=n.pre;
insertFirst(n);
}
} public class LRUCache {
Map<Integer,Node> map;
CacheList cacheList;
int capacity;
public LRUCache(int capacity) {
map = new HashMap<Integer,Node>();
cacheList= new CacheList(capacity);
this.capacity=capacity;
} public int get(int key) {
if(map.get(key)==null)
return -1;
else {
Node n= (Node) map.get(key);
cacheList.shiftToFirst(n);
return n.value;
}
} public void set(int key, int value) {
if(map.containsKey(key)){
Node come= (Node) map.get(key);
come.value=value;
cacheList.shiftToFirst(come);;
}else{
if(map.size()==capacity){
Node old=cacheList.removeLast();
map.remove(old.key); }
Node nn=new Node(key,value);
cacheList.insertFirst(nn);
map.put(key, nn);
} }
public static void main(String[] args){
LRUCache l = new LRUCache(1);
l.set(2, 1);
System.out.println(l.get(2));
l.set(3, 2);
System.out.println(l.get(2));
System.out.println(l.get(3)); }
}
leetcode--003 LRU 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 ...
- LeetCode之LRU Cache 最近最少使用算法 缓存设计
设计并实现最近最久未使用(Least Recently Used)缓存. 题目描述: Design and implement a data structure for Least Recently ...
- leetcode@ [146] LRU Cache (TreeMap)
https://leetcode.com/problems/lru-cache/ Design and implement a data structure for Least Recently Us ...
- 【LeetCode】LRU Cache 解决报告
插话:只写了几个连续的博客,博客排名不再是实际"远在千里之外"该.我们已经进入2一万内. 再接再厉.油! Design and implement a data structure ...
- [LeetCode] 146. LRU Cache 最近最少使用页面置换缓存器
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the fol ...
- [LeetCode] 146. LRU Cache 近期最少使用缓存
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the fol ...
- 【leetcode】LRU Cache
题目简述: Design and implement a data structure for Least Recently Used (LRU) cache. It should support t ...
- 【leetcode】LRU Cache(hard)★
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the fol ...
- 【Leetcode】 LRU Cache实现
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the fol ...
- leetcode 146. LRU Cache ----- java
esign and implement a data structure for Least Recently Used (LRU) cache. It should support the foll ...
随机推荐
- 单独谈谈 Android Cursor 的使用细节
使用过 SQLite 数据库对 Cursor 应该不陌生,这里单独拿出来谈一下,加深对Android SQLite中使用 Cursor 的理解. 在你理解和使用 Android Cursor 的时候你 ...
- windows下spark开发环境配置
http://www.cnblogs.com/davidwang456/p/5032766.html windows下spark开发环境配置 --本篇随笔由同事葛同学提供. windows下spark ...
- sublime使用方法
一.sublime菜单简介[常用功能及快捷键] [Edit菜单] 1.line行操作快捷键 ctrl+] 增加缩进 ctrl+[ 减小缩进 ctrl+shift+D 复制当前行 ctrl+shift+ ...
- mysql链接表,connection string, federated engine
http://database.51cto.com/art/201011/234561.htm
- Request 地址栏传值
request页面 protected void btnSearch_Click(object sender, EventArgs e) { Response.Redirect("Reque ...
- List和ArrayList之间转换的例子
package Test01; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public c ...
- multipleOutputs Hadoop
package org.lukey.hadoop.muloutput; import java.io.IOException; import org.apache.hadoop.conf.Config ...
- HDU 2897 邂逅明下(巴什博奕变形)
巴什博奕的变形,与以往巴什博奕不同的是,这里给出了上界和下界,原先是(1,m),现在是(p,q),但是原理还是一样的,解释如下: 假设先取者为A,后取者为B,初始状态下有石子n个,除最后一次外其他每次 ...
- 解决Ubuntu系统中文乱码显示问题,终端打开文件及查看目录
解决Ubuntu系统中文乱码显示问题 [日期:2014-02-20] 来源:Linux社区 作者:njchenyi [字体:大 中 小] 我是先安装了Ubuntu 12.04 Server,然后 ...
- zencart 具体页面调用规则: $body_code变量解析
zencart $body_code变量解析 修改centerColumn 可以修改中间产品方框的大小 2.2.5 .BODY文件在这个文件生效 require($body_code) include ...