Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions CloneLinkedListRandomPointer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution:
def copyRandomList(self, head: 'Node') -> 'Node':
if not head:
return None
hash_map={}
temp=head
while temp:
hash_map[temp]=Node(temp.val)
temp=temp.next
temp=head
while temp:
if not temp.next:
hash_map[temp].next=None
else:
hash_map[temp].next=hash_map[temp.next]
if temp.random==None :
hash_map[temp].random=None
else:
hash_map[temp].random=hash_map[temp.random]
temp=temp.next
return hash_map[head]