由买买提看人间百态

topics

全部话题 - 话题: copyhead
(共0页)
g****v
发帖数: 971
1
来自主题: JobHunting版 - 请教下copy list with random pointer
我的代码在我自己机器上没问题,但leetcode上连最简单的case都通不过。
比如 [-1, #] 都没通过。
实在是找不出问题,请大家看看。
----------------------------------------------------------------------------
------------------
RandomListNode *copyRandomList(RandomListNode *head) {
if(head == NULL) return NULL;
RandomListNode *copyhead = new RandomListNode(head->label);
copyhead->random = head->random;
RandomListNode *ori = head->next;
RandomListNode *oritemp;
head->next = copyhead;
RandomListNode ... 阅读全帖
p****U
发帖数: 109
2
来自主题: JobHunting版 - leetcode Copy List with Random Pointer
RandomListNode *copyRandomList(RandomListNode *head) {
// Note: The Solution object is instantiated only once and is reused by
each test case.
//first parse
if(!head)
return NULL;
RandomListNode *cur=head;
while(cur){
RandomListNode *tmp=cur->next;
cur->next=new RandomListNode(cur->label);
cur=cur->next;
cur->next=tmp;
cur=cur->next;
}
//second parse
cur=head;
RandomListNode *copy;
while(cur){
copy=cu... 阅读全帖
(共0页)