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