第八周
- Alogrithm:LRU Cache
- Reading:AWS re:Invent 2018: Running Serverless at The Edge (CTD302)
- Tech:DNS探秘
- Share:clion远程调试指南
Alogrithm
题目—LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.
get(key)
- Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.put(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.
Follow up:
Could you do both operations in O(1) time complexity?
Example:
1 | LRUCache cache = new LRUCache( 2 /* capacity */ ); |
首先,对于cache,如果希望有O(1)的查找复杂度,肯定要用hashmap来保存key和对象的映射。同时用双向链表构建LRU很方便。
1 | /** |
Tips:
- LeetCode 报错解决 heap-buffer-overflow Heap-use-after-free Stack-buffer-overflow Global-buffer-overflow
- O(1)查找复杂度,肯定要用hashmap来保存key和对象的映射。
Reading
AWS re:Invent 2018: Running Serverless at The Edge (CTD302)
AWS的边缘计算实践
Tech
DNS探秘:DNS探秘