Documentation
¶
Overview ¶
Package lru_cache https://leetcode-cn.com/problems/lru-cache/
146. LRU 缓存
请你设计并实现一个满足 LRU (最近最少使用) 缓存 约束的数据结构。
实现 LRUCacheO1 类:
- LRUCacheO1(int capacity) 以 正整数 作为容量 capacity 初始化 LRU 缓存
- int get(int key) 如果关键字 key 存在于缓存中,则返回关键字的值,否则返回 -1 。
- void put(int key, int value) 如果关键字 key 已经存在,则变更其数据值 value ; 如果不存在,则向缓存中插入该组 key-value 。 如果插入操作导致关键字数量超过 capacity ,则应该 逐出 最久未使用的关键字。
函数 get 和 put 必须以 O(1) 的平均时间复杂度运行。
提示:
1 <= capacity <= 3000 0 <= key <= 10000 0 <= value <= 10^5 最多调用 2 * 10^5 次 get 和 put
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DLinkedNode ¶
type DLinkedNode struct {
// contains filtered or unexported fields
}
type LRUCache ¶
type LRUCache struct {
// contains filtered or unexported fields
}
func Constructor ¶
type LRUCacheO1 ¶
type LRUCacheO1 struct {
// contains filtered or unexported fields
}
func ConstructorO1 ¶
func ConstructorO1(capacity int) LRUCacheO1
func (*LRUCacheO1) Get ¶
func (this *LRUCacheO1) Get(key int) int
func (*LRUCacheO1) Put ¶
func (this *LRUCacheO1) Put(key int, value int)
type LRUCacheS1 ¶
type LRUCacheS1 struct {
// contains filtered or unexported fields
}
func ConstructorS1 ¶
func ConstructorS1(capacity int) LRUCacheS1
func (*LRUCacheS1) Get ¶
func (this *LRUCacheS1) Get(key int) int
func (*LRUCacheS1) Put ¶
func (this *LRUCacheS1) Put(key int, value int)
Click to show internal directories.
Click to hide internal directories.