码迷,mamicode.com
首页 > 系统相关 > 详细

LeetCode 460. LFU Cache

时间:2019-11-02 13:56:42      阅读:83      评论:0      收藏:0      [点我收藏+]

标签:nbsp   一个   strong   cache   nod   iterator   根据   hashtable   插入   

 

Hashtable + BST

用hashtable保存key->Node,另外用一个set<Node>来根据freq和time进行排序,保证容量满时删除的是lfu的节点。

注意这里hashtable的value存的是Node,不是指针也不是set的iterator。因为用指针只能做到从set里删除O(1),而set的插入还是O(logn)的,总的时间复杂度O(logn).。

LeetCode 460. LFU Cache

标签:nbsp   一个   strong   cache   nod   iterator   根据   hashtable   插入   

原文地址:https://www.cnblogs.com/hankunyan/p/11781272.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!