@@ -0,0 +1,1149 @@
+class LRUCache(object):%0A%0A    def __init__(self, capacity):%0A        %22%22%22%0A        :type capacity: int%0A        %22%22%22%0A        self.num = capacity%0A        self.l = %5B%5D%0A        self.keys = %7B%7D        %0A%0A    def get(self, key):%0A        %22%22%22%0A        :type key: int%0A        :rtype: int%0A        %22%22%22%0A        if self.keys.has_key(key):%0A            self.l.remove(key)%0A            self.l.insert(0,key)%0A            return self.keys%5Bkey%5D%0A        else:%0A            return -1        %0A%0A    def put(self, key, value):%0A        %22%22%22%0A        :type key: int%0A        :type value: int%0A        :rtype: None%0A        %22%22%22%0A        if self.keys.has_key(key):%0A            self.l.remove(key)%0A        elif len(self.l) == self.num:%0A            trash = self.l.pop()%0A            self.keys.pop(trash)%0A%0A        self.keys%5Bkey%5D = value%0A        self.l.insert(0, key)%0A%0Acache = LRUCache(2) %0Acache.put(1, 1)%0Acache.put(2, 2)%0Aprint cache.get(1)       # returns 1%0Acache.put(3, 3)    # evicts key 2%0Aprint cache.get(2)       # returns -1 (not found)%0Acache.put(4, 4)    # evicts key 1%0Aprint cache.get(1)       # returns -1 (not found)%0Aprint cache.get(3)       # returns 3%0Aprint cache.get(4)       # returns 4%0A

add lru