```
class ListNode:
def __init__(self, val):
self.val = val
self.next = None
self.prev = None
class LRUCache:
# @param capacity, an integer
def __init__(self, capacity):
self.capacity = capacity
self.dic = {}
self.head = None
self.length = 0
# @return an integer
def get(self, key):
if key in self.dic:
cur = self.head
while cur.val != key:
cur = cur.next
if cur != self.head:
prev = cur.prev
next = cur.next
prev.next = next
if next:
next.prev = prev
self.head.prev = cur
cur.next = self.head
cur.prev = None
self.head = cur
return self.dic[key]
return -1
# @param key, an integer
# @param value, an integer
# @return nothing
def set(self, key, value):
if key in self.dic:
self.dic[key] = value
cur = self.head
while cur.val != key:
cur = cur.next
if cur != self.head:
prev = cur.prev
next = cur.next
prev.next = next
if next:
next.prev = prev
self.head.prev = cur
cur.next = self.head
cur.prev = None
self.head = cur
else:
self.dic[key] = value
if self.length < self.capacity:
self.length += 1
cur = ListNode(key)
if self.head:
cur.next = self.head
self.head.prev = cur
self.head = cur
else:
if self.capacity == 1:
del self.dic[self.head.val]
self.head.val = key
else:
cur = self.head
while cur.next:
cur = cur.next
del self.dic[cur.val]
cur.prev.next = None
cur.val = key
cur.next = self.head
self.head.prev = cur
cur.prev = None
self.head = cur
```

If I use Python list, it works; However, I create a double linked list (this version) and single linked list and they cannot pass, TLE.

What's wrong with it?