← 返回 apple 的题目列表LFU Cache
类型:qbank
Design and implement a data structure for a Least Frequently Used (LFU) cache.
Examples
Example 1:
Input: ["LFUCache","put","put","get","put","get","get","put","get","get","get"] [[2],[1,1],[2,2],[1],[3,3],[2],[3],[4,4],[1],[3],[4]]
Output: [null,null,null,1,null,-1,3,null,-1,3,4]
Explanation:
Example 2:
Input: ["LFUCache","put","get"] [[0],[1,1],[1]]
Output: [null,null,-1]
Explanation:
Capacity 0 means nothing is ever stored.
Constraints
0 <= capacity <= 10^4
0 <= key <= 10^5
0 <= value <= 10^9
At most 2 * 10^5 calls to get and put