leetcode

package
v0.0.0-...-250739b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2022 License: MIT Imports: 3 Imported by: 0

README

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Heap

type Heap []int

func (*Heap) Pop

func (h *Heap) Pop() int

func (*Heap) Push

func (h *Heap) Push(val int)

type LFUCache

type LFUCache struct {
	// contains filtered or unexported fields
}

func Constructor

func Constructor(capacity int) LFUCache

func (*LFUCache) Get

func (this *LFUCache) Get(key int) int

func (*LFUCache) Put

func (this *LFUCache) Put(key int, value int)

type LFUData

type LFUData struct {
	// contains filtered or unexported fields
}

func (*LFUData) Add

func (this *LFUData) Add(key, val int)

func (*LFUData) Get

func (this *LFUData) Get(key int) int

func (*LFUData) HasKey

func (this *LFUData) HasKey(key int) bool

func (*LFUData) Index

func (this *LFUData) Index(key int) int

func (LFUData) Len

func (this LFUData) Len() int

func (LFUData) Less

func (this LFUData) Less(i, j int) bool

func (*LFUData) Pop

func (this *LFUData) Pop() interface{}

func (*LFUData) Push

func (this *LFUData) Push(x interface{})

func (*LFUData) Remove

func (this *LFUData) Remove()

func (*LFUData) Replace

func (this *LFUData) Replace(key, val int)

func (*LFUData) SetIndex

func (this *LFUData) SetIndex(key, idx int)

func (LFUData) Swap

func (this LFUData) Swap(i, j int)

type LFUItem

type LFUItem struct {
	// contains filtered or unexported fields
}

460. LFU Cache

Design and implement a data structure for a Least Frequently Used (LFU) cache. Implement the LFUCache class:

  • LFUCache(int capacity) Initializes the object with the capacity of the data structure.
  • int get(int key) Gets the value of the key if the key exists in the cache. Otherwise, returns -1.
  • void put(int key, int value) Update the value of the key if present, or inserts the key if not already present. When the cache reaches its capacity, it should invalidate and remove the least frequently used key before inserting a new item. For this problem, when there is a tie (i.e., two or more keys with the same frequency), the least recently used key would be invalidated.

To determine the least frequently used key, a use counter is maintained for each key in the cache. The key with the smallest use counter is the least frequently used key. When a key is first inserted into the cache, its use counter is set to 1 (due to the put operation). The use counter for a key in the cache is incremented either a get or put operation is called on it. The functions get and put must each run in O(1) average time complexity.

Runtime: 682 ms, faster than 90.00% of Go online submissions for LFU Cache. Memory Usage: 85.9 MB, less than 42.50% of Go online submissions for LFU Cache.

func (*LFUItem) Count

func (this *LFUItem) Count() int

func (*LFUItem) Data

func (this *LFUItem) Data() int

func (*LFUItem) Flush

func (this *LFUItem) Flush()

func (*LFUItem) Key

func (this *LFUItem) Key() int

func (*LFUItem) SetData

func (this *LFUItem) SetData(data int)

func (*LFUItem) SetVersion

func (this *LFUItem) SetVersion(v int)

func (LFUItem) String

func (this LFUItem) String() string

func (*LFUItem) Version

func (this *LFUItem) Version() int

type ListNode

type ListNode = structure.ListNode

type PriorityQueue

type PriorityQueue []*ListNode

func (PriorityQueue) Len

func (q PriorityQueue) Len() int

func (PriorityQueue) Less

func (q PriorityQueue) Less(i, j int) bool

func (*PriorityQueue) Pop

func (q *PriorityQueue) Pop() interface{}

func (*PriorityQueue) Push

func (q *PriorityQueue) Push(x interface{})

func (PriorityQueue) Swap

func (q PriorityQueue) Swap(i, j int)

type TreeNode

type TreeNode = structure.TreeNode

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL