public class Solution {
public RandomListNode copyRandomList(RandomListNode head) {
RandomListNode str=head;
while(head.next!=null){
RandomListNode x= new RandomListNode(head.label);
x.next=head.next;
x.random=head.random;
head.next=x;
head=x.next;
// x=head.next;
}
head=str;
// head=head.next;
while(head.random.next!=null){
head.next.random=head.random.next;
head=head.next.next;
}
head=str;
// head= head.next;
while(head.next.next.next!=null){
head.next.next=head.next.next.next;
head=head.next;
}
return str.next;
}
}
I dont understand what is going wrong, Answer is right but this statement is comming again and again “You seem to have created duplicate nodes for the sake of random pointers.”