@@ -0,0 +1,1488 @@
+# Definition for singly-linked list with a random pointer.%0A# class RandomListNode:%0A#     def __init__(self, x):%0A#         self.label = x%0A#         self.next = None%0A#         self.random = None%0Aclass Solution:%0A    # @param head: A RandomListNode%0A    # @return: A RandomListNode%0A    def copyRandomList(self, head):%0A        # write your code here%0A%0A        # Solution 1%0A        # dummy = RandomListNode(0)%0A        # tmp = dummy%0A        # tmp2 = head%0A        # hashmap = %7B%7D%0A        # while (tmp2):%0A        #     tmp.next = RandomListNode(tmp2.label)%0A        #     hashmap%5Btmp2.label%5D = tmp.next%0A        #     tmp = tmp.next%0A        #     tmp2 = tmp2.next%0A        # tmp2 = head%0A        # tmp = dummy%0A        # while (tmp2):%0A        #     tmp.next.random = hashmap%5Btmp2.random.label%5D if tmp2.random else None%0A        #     tmp = tmp.next%0A        #     tmp2 = tmp2.next%0A        # return dummy.next%0A%0A        # Solution 2%0A        if (not head):%0A            return None%0A        tmp = head%0A        while (tmp):%0A            rest = tmp.next%0A            tmp.next = RandomListNode(tmp.label)%0A            tmp.next.next = rest%0A            tmp = tmp.next.next%0A        tmp = head%0A        while (tmp):%0A            if (tmp.random):%0A                tmp.next.random = tmp.random.next%0A            tmp = tmp.next.next%0A        dummy = RandomListNode(0)%0A        tmp = dummy%0A        while (head):%0A            tmp.next = head.next%0A            head = head.next.next%0A            tmp = tmp.next%0A        return dummy.next%0A

Add solution to lintcode question 105