由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 请教下copy list with random pointer
相关主题
copy link with random additional pointers哪位大侠帮我看看这个code
Leetcode新题 Copy List with Random PointerPopulating Next Right Pointers in Each Node II
Leetcode Copy List with Random Pointer Runtime Error?leetcode populating next pointer 2
leetcode Copy List with Random Pointer请问大牛们如何提高解决leetcode上面Linkedlist的题的能力?
求救! Copy List With Random Pointer总是超时bloomberg 电话面试问题
各位刷友,leetcode里的题目:Copy List with Random Pointer问到linked list 的题目
copy list with random pointer 老出错什么情况下pass by reference比pass by pointer好?
reverse random pointers of a single linked listlinklist exercise
相关话题的讨论汇总
话题: copy话题: copyhead话题: random话题: ori
进入JobHunting版参与讨论
1 (共1页)
g****v
发帖数: 971
1
我的代码在我自己机器上没问题,但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 *copy = copyhead;
//copy to a new list "copyhead"
while(ori != NULL)
{
RandomListNode *copytemp = new RandomListNode(ori->label);
copytemp->random = ori->random;
copy->next = copytemp;;
oritemp = ori->next;
ori->next = copytemp;
ori = oritemp;
copy = copy->next;
}
//assign the random pointers
copy = copyhead;
while(copy != NULL)
{
if(copy->random != NULL)
copy->random = copy->random->next;
copy = copy->next;
}
return copyhead;
}
g****v
发帖数: 971
2
lc给出的output是:
Next pointer of node with label -1 from the original list was modified.
l*****a
发帖数: 14598
3
你把原来的list恢复原状了吗

【在 g****v 的大作中提到】
: lc给出的output是:
: Next pointer of node with label -1 from the original list was modified.

g****v
发帖数: 971
4
但原来的是不是const的,需要恢复么?

【在 l*****a 的大作中提到】
: 你把原来的list恢复原状了吗
U**m
发帖数: 313
5
This is a link list

【在 g****v 的大作中提到】
: 但原来的是不是const的,需要恢复么?
1 (共1页)
进入JobHunting版参与讨论
相关主题
linklist exercise求救! Copy List With Random Pointer总是超时
One question about Void pointer (转载)各位刷友,leetcode里的题目:Copy List with Random Pointer
问个C的基本问题copy list with random pointer 老出错
why strlen library function doesn't check NULL pointerreverse random pointers of a single linked list
copy link with random additional pointers哪位大侠帮我看看这个code
Leetcode新题 Copy List with Random PointerPopulating Next Right Pointers in Each Node II
Leetcode Copy List with Random Pointer Runtime Error?leetcode populating next pointer 2
leetcode Copy List with Random Pointer请问大牛们如何提高解决leetcode上面Linkedlist的题的能力?
相关话题的讨论汇总
话题: copy话题: copyhead话题: random话题: ori