Created
July 4, 2017 08:12
-
-
Save enijkamp/2d1783ab33470d3bc79cc64ea94f729d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution(object): | |
def copyRandomList(self, head): | |
if head == None: return None | |
map_to_copy = {} | |
node = head | |
while node != None: | |
node_copy = RandomListNode(node.label) | |
map_to_copy[node] = node_copy | |
node = node.next | |
node = head | |
while node != None: | |
node_copy = map_to_copy[node] | |
if node.next: node_copy.next = map_to_copy[node.next] | |
if node.random: node_copy.random = map_to_copy[node.random] | |
node = node.next | |
return map_to_copy[head] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment