# Copy List with Random Pointer (Leetcode 138)

Problem Link: <https://leetcode.com/problems/copy-list-with-random-pointer/description/>

```python
"""
# Definition for a Node.
class Node:
    def __init__(self, x: int, next: 'Node' = None, random: 'Node' = None):
        self.val = int(x)
        self.next = next
        self.random = random
"""

class Solution:
    def copyRandomList(self, head: 'Optional[Node]') -> 'Optional[Node]':

        oldToCopy = {None: None}
        curr=head
        while(curr is not None):
            oldToCopy[curr]=Node(curr.val)
            curr=curr.next
        
        curr=head
        while(curr is not None):
            copy=oldToCopy[curr]
            copy.next=oldToCopy[curr.next]
            copy.random=oldToCopy[curr.random]
            curr=curr.next
        
        return oldToCopy[head]
```
