当前位置:网站首页>LRU cache
LRU cache
2022-06-23 03:33:00 【A shaggy haired obeisance】
146. LRU cache - Power button (LeetCode) (leetcode-cn.com)
OrderedDict: Sort by default according to the order in which the elements are placed

class LRUCache(object):
def __init__(self, capacity):
"""
:type capacity: int
"""
self.dic=collections.OrderedDict()
self.remain=capacity
def get(self, key):
"""
:type key: int
:rtype: int
"""
if key not in self.dic:
return -1
v=self.dic.pop(key)
self.dic[key]=v
return v
def put(self, key, value):
"""
:type key: int
:type value: int
:rtype: None
"""
if key in self.dic:
self.dic.pop(key)
else:
if self.remain>0:
self.remain-=1
else:
self.dic.popitem(last=False)
self.dic[key]=value
# Your LRUCache object will be instantiated and called as such:
# obj = LRUCache(capacity)
# param_1 = obj.get(key)
# obj.put(key,value)边栏推荐
- Eight models of data analysis: detailed explanation of RFM model
- Gx3001q UI instructions for upgrading 8-bit color to 16 bit color
- Why don't I suggest you use "! = null" to judge empty space?
- WPF developer essential control library newbeecoder UI —NbMessageBox
- Stress testing with locust on rainbow
- How to share small programs released by wechat
- Weekly Postgres world news 2022w03
- Form submit onclick and onsubmit
- Micro build low code to realize user login and registration
- JS asynchronous mechanism
猜你喜欢

Fetch request details
![Analysis on the development status of China's watch industry in 2021: a large number of electric watches are imported [figure]](/img/ca/672bfe49c8123da8679b2abeb43a2e.jpg)
Analysis on the development status of China's watch industry in 2021: a large number of electric watches are imported [figure]
![Analysis on demand and market scale of China's steamed stuffed bun industry in 2020 [figure]](/img/4b/dd272f98b89a157180bf68570d2763.jpg)
Analysis on demand and market scale of China's steamed stuffed bun industry in 2020 [figure]

Analysis on the development of duty-free industry in Hainan Province in 2021: the implementation of the new policy makes the duty-free market in Hainan more "prosperous" [figure]

Gakataka student end to bundle Version (made by likewendy)

Encryption related to returnee of national market supervision public service platform
![Analysis on the development prospect of China's brain computer interface industry in 2021: wide application prospect, sustained and rapid growth of market scale [figure]](/img/84/192d152ceb760264b6b555b321f129.jpg)
Analysis on the development prospect of China's brain computer interface industry in 2021: wide application prospect, sustained and rapid growth of market scale [figure]
![Analysis on development history, industrial chain, output and enterprise layout of medical polypropylene in China in 2020 [figure]](/img/28/ebfc25ec288627706e15a07e6bdb77.jpg)
Analysis on development history, industrial chain, output and enterprise layout of medical polypropylene in China in 2020 [figure]
![Analysis of China's integrated circuit industry chain in 2021: huge downstream market demand [figure]](/img/de/d73805aaf4345ca3d2a7baf85aab8d.jpg)
Analysis of China's integrated circuit industry chain in 2021: huge downstream market demand [figure]

Jmeter- (V) simulated user concurrent login for interface test
随机推荐
Operating wechat cache by using wechat low code
What are the advantages of the completely free and open source flutter? How to learn about flutter?
JS to determine whether the page is opened for the first time today
Flink practice tutorial: advanced 7- basic operation and maintenance
[Alibaba middleware technology series] "Nacos technology" service registration and discovery related principle analysis
Aiot application innovation competition - Smart street lamp (developed with keil)
Goframe framework (RK boot): enable tls/ssl
Tachometer script
Stress testing with locust on rainbow
Build a weather forecast applet using a widget
How does easyplayer embed a video snapshot into a demo?
Hierarchical attention graph convolution network for interpretable recommendation based on knowledge graph
Know res.send() and res.end() of Express
Troubleshooting and solution of error 400 in easygbs video platform
Application of map function in JS
How to share small programs released by wechat
The difference between code39 and code93
Wwdc21 - App store server API practice summary
MIT 6. S081/fall 2020 build risc-v and xv6 development and debugging environment
Integrate Tencent maps with micro build and low code