Copy List with Random Pointer (LC-0138)
class Solution:
def copyRandomList(self, head):
cache = {}
temp = head
while temp:
cache[temp] = Node(temp.val, None, None)
temp = temp.next
temp = head
while temp:
cache[temp].next = cache.get(temp.next)
cache[temp].random = cache.get(temp.random)
temp = temp.next
return cache.get(head)