My Blog List

Showing posts with label Leetcode_STL. Show all posts
Showing posts with label Leetcode_STL. Show all posts

[Leetcode Solution] LRU Cache

Good Problem

Analysis

  • In order to implement a LRU cache which has get and set operation. And each operation should be constant time.
  • Because the feature of LRU, previous used node should be transferred as latest. Thus a linked list type data structure should be applied. 
  • In order to achieve constant time for get, obviously a hash table will be used which maintains the mapping from the key to value. However the value is stored at linked list and the list is mutable.