携程lru***算法,本地没有问题,线上越界,求帮忙
# 线下没有问题,线上一直越界,求大佬们帮忙看看是什么问题,谢谢 import sys class LRUCache(object): def __init__(self, size=5): self.size = size self.*** = dict() self.key = [] def get(self, key): if self.***.has_key(key): self.key.remove(key) self.key.insert(0, key) return self.***[key] else: return -1 def set(self, key, value): if self.***.has_key(key): self.***.pop(key) self.***[key] = value elif len(self.***) == self.size: old_key = self.key.pop() self.***.pop(old_key) self.key.insert(0, key) self.***[key] = value else: self.***[key] = value self.key.insert(0, key) if __name__ == '__main__': size = int(sys.stdin.readline().strip()) lru = LRUCache(size) while True: oper = sys.stdin.readline().strip().split(' ') if oper[0] == 'p': lru.set(oper[1], oper[2]) else: print lru.get(oper[1])
#携程##uc#