不太理解为什么这么做,一遍遍历老链表的同时创建新链表不行吗?就像这样的吧: public RandomListNode Clone(RandomListNode pHead) { if(pHead == null) return null; RandomListNode head = null; RandomListNode result = null; while(pHead != null){ if(head == null) head = new RandomListNode(pHead.label); else{ head.next = new RandomListNode(pHead.label); head = head.next; } if(result == null) result = head; if(pHead.random != null) head.random = new RandomListNode(pHead.random.label); pHead = pHead.next; } return result; }
点赞

相关推荐

大摆哥:刚好要做个聊天软件,直接让你帮他干活了
点赞 评论 收藏
分享
04-06 11:24
已编辑
太原学院 C++
点赞 评论 收藏
分享
牛客网
牛客企业服务