首页 > 代码库 > LeetCode 146 LRU Cache

LeetCode 146 LRU Cache

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.

get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.
set(key, value) - Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item.

思路:HashMap+双链表
class Node {
	Node pre;
	Node next;
	int key;
	int value;

	Node(int k, int val) {
		key = k;
		value = http://www.mamicode.com/val;>

LeetCode 146 LRU Cache