标签:
/* public class RandomListNode { int label; RandomListNode next = null; RandomListNode random = null; RandomListNode(int label) { this.label = label; } } */ public class Solution { public RandomListNode Clone(RandomListNode pHead) { RandomListNode Head=pHead; if(pHead==null){ return null; } RandomListNode cur=pHead; RandomListNode next=pHead; while(cur!=null){ next=cur.next; cur.next=new RandomListNode(cur.label); cur.next.next=next; cur=next; } cur=pHead; next=pHead; while(cur!=null){ cur.next.random=cur.random==null?null:cur.random.next; cur=cur.next.next;; } RandomListNode pHead1=Head.next; while(Head!=null){ next=Head.next.next; Head.next.next=next==null?null:next.next; Head.next=next; Head=next; } return pHead1; } }
标签:
原文地址:http://www.cnblogs.com/tobemaster/p/5903669.html