@@ -0,0 +1,1380 @@
+%0A/**%0A*Question Description:%0A*%0A*A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.%0A*%0A*Return a deep copy of the list.%0A*%0A**/%0A%0A%0A/**%0A*My Solution:(Java)%0A**/%0A%0A%0A%0A/**%0A * Definition for singly-linked list with a random pointer.%0A * class RandomListNode %7B%0A *     int label;%0A *     RandomListNode next, random;%0A *     RandomListNode(int x) %7B this.label = x; %7D%0A * %7D;%0A */%0Apublic class Solution %7B%0A    public RandomListNode copyRandomList(RandomListNode head) %7B%0A        %0A        if(head==null)%0A          return head;%0A          %0A        RandomListNode cHead = new RandomListNode(head.label);%0A        HashMap%3CRandomListNode,RandomListNode%3E map = new HashMap%3CRandomListNode,RandomListNode%3E();%0A        map.put(head,cHead);%0A        %0A        RandomListNode cNode = cHead;%0A        RandomListNode pNode = head.next;%0A        while(pNode !=null)%0A        %7B%0A            RandomListNode tempNode = new RandomListNode(pNode.label);%0A            map.put(pNode,tempNode);%0A            cNode.next = tempNode;%0A            cNode = tempNode;%0A            pNode = pNode.next;%0A%0A        %7D%0A        %0A        cNode = cHead;%0A        pNode = head;%0A        while(pNode !=null)%0A        %7B%0A            cNode.random = map.get(pNode.random);%0A            cNode = cNode.next;%0A            pNode = pNode.next;%0A        %7D%0A        %0A        return cHead;%0A%0A%7D%0A%7D%0A

Copy List With Random Pointer