The result is different from when I run with my own system


  • 0
    L
    class LRUCache(object):
    q=[]
    d={}
    cap=0
    def __init__(self, capacity):
    	self.cap=capacity
    
    def get(self, key):
    	if key not in self.d:
    		return -1
    	else:
    		self.q.remove(key)
    		self.q.insert(0,key)
    		return self.d[key]
    
    def set(self, key, value):
    	if key in self.d:
    		self.d[key]=value
    		self.q.remove(key)
    		self.q.insert(0,key)
    		return
    	if len(self.q)>=self.cap:
    		self.d.pop(self.q.pop(),None)
    	self.q.insert(0,key)
    	self.d[key]=value
    

    When I run in my system, get(2) gives -1, but in oj, it gives 3. I didn't see any logic to give a 3, the dict is empty!


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.