add: add repr method
This commit is contained in:
+7
-1
@@ -4,6 +4,9 @@ class LRUCache:
|
|||||||
self.capacity = capacity
|
self.capacity = capacity
|
||||||
self.slots = []
|
self.slots = []
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return ", ".join(map(lambda x: str(x), self.slots))
|
||||||
|
|
||||||
def get(self, key: int) -> int:
|
def get(self, key: int) -> int:
|
||||||
if key <= len(self.slots) -1:
|
if key <= len(self.slots) -1:
|
||||||
return self.slots[key]
|
return self.slots[key]
|
||||||
@@ -21,7 +24,10 @@ def main():
|
|||||||
print(cache.get(0))
|
print(cache.get(0))
|
||||||
|
|
||||||
cache.put(0,1)
|
cache.put(0,1)
|
||||||
print(cache.get(0))
|
print(cache)
|
||||||
|
|
||||||
|
cache.put(1,2)
|
||||||
|
print(cache)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
Reference in New Issue
Block a user