init: initial commit
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
class LRUCache:
|
||||
|
||||
def __init__(self, capacity: int):
|
||||
self.capacity = capacity
|
||||
self.slots = []
|
||||
|
||||
def get(self, key: int) -> int:
|
||||
if key <= len(self.slots) -1:
|
||||
return self.slots[key]
|
||||
return -1
|
||||
|
||||
def put(self, key: int, value: int) -> None:
|
||||
if self.capacity > len(self.slots):
|
||||
self.slots.append(value)
|
||||
else:
|
||||
self.slots[len(self.slots) - 1] = value
|
||||
|
||||
def main():
|
||||
cache = LRUCache(2)
|
||||
print(cache.get(1))
|
||||
print(cache.get(0))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user