由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Leetcode Copy List with Random Pointer Runtime Error?
相关主题
哪位大侠帮我看看这个code新题gas station,献丑了,没过一个case,帮看看
Leetcode新题 Copy List with Random Pointercopy link with random additional pointers
leetcode Copy List with Random Pointerreverse random pointers of a single linked list
各位刷友,leetcode里的题目:Copy List with Random Pointer这段代码在leetcode上面跑不了??
copy list with random pointer 老出错leetcode 上通不过
请教下copy list with random pointerleetcode pow runtime error??
求救! Copy List With Random Pointer总是超时leetcode Parlindrome Partition run time error
请问大牛们如何提高解决leetcode上面Linkedlist的题的能力?请教LEETCODE讲解部分的LCA一道题的变种。。
相关话题的讨论汇总
话题: pointer话题: res话题: null话题: next
进入JobHunting版参与讨论
1 (共1页)
S********0
发帖数: 29
1
话不多说直接上代码,在本地测了没发现问题。。
谢谢.....
public static RandomListNode copyRandomList(RandomListNode head) {
// Note: The Solution object is instantiated only once and is reused
by each test case.
if(head == null) return null;
RandomListNode pointer, res_pointer;
pointer = head;
while(pointer != null){
RandomListNode temp = new RandomListNode(pointer.label);
temp.random = null;
temp.next = pointer.next;
RandomListNode next = pointer.next;
pointer.next = temp;
pointer = next;
}
pointer = head;
while(pointer != null){
pointer.next.random = pointer.random.next;
pointer = pointer.next.next;
}
pointer = head;
RandomListNode res = head.next;
res_pointer = res;
while(pointer != null && res_pointer != null){
pointer.next = pointer.next.next;
if(res_pointer.next != null) res_pointer.next = res_pointer.next
.next;
pointer = pointer.next;
res_pointer = res_pointer.next;
}
return res;
}
c********w
发帖数: 2438
2
第二个while循环
copy random的时候
如果原random是null怎么办
不就run time error了
所以要处理
if(pointer.random!=null)
S********0
发帖数: 29
3
谢谢,我真是粗心。
1 (共1页)
进入JobHunting版参与讨论
相关主题
请教LEETCODE讲解部分的LCA一道题的变种。。copy list with random pointer 老出错
leetcode彻底挂了么请教下copy list with random pointer
LeetCode Jump Game [Runtime Error]求救! Copy List With Random Pointer总是超时
LeetCode RunTime Error一问请问大牛们如何提高解决leetcode上面Linkedlist的题的能力?
哪位大侠帮我看看这个code新题gas station,献丑了,没过一个case,帮看看
Leetcode新题 Copy List with Random Pointercopy link with random additional pointers
leetcode Copy List with Random Pointerreverse random pointers of a single linked list
各位刷友,leetcode里的题目:Copy List with Random Pointer这段代码在leetcode上面跑不了??
相关话题的讨论汇总
话题: pointer话题: res话题: null话题: next