雅灭蝶!!# Joke - 肚皮舞运动
A*g
1 楼
过不了,请大牛看看, 我在本地测试过好像没问题啊
----------------------------------------------
public class Solution {
public RandomListNode copyRandomList(RandomListNode head) {
if (head==null) return null;
RandomListNode p = head;
while (p != null) {
RandomListNode newNode = new RandomListNode(p.label);
newNode.next = p.next;
p.next = newNode;
p = newNode.next;
}
p = head;
RandomListNode p2 = head.next;
RandomListNode newHead = p2;
while (p2.next != null) {
if (p.random==null) {
p2.random = null;
} else {
p2.random = p.random.next;
}
p.next = p2.next;
p = p.next;
p2.next = p.next;
p2 = p2.next;
}
p.next = null;
return newHead;
}
}
--------------------------------------------------
Submission Result: Wrong Answer
Input: {-1,-1}
Output: {-1,#}
Expected: {-1,-1}
不明白这个{-1,#}什么意思,但是本机测试可以通过-1,-1啊...
谢谢!
----------------------------------------------
public class Solution {
public RandomListNode copyRandomList(RandomListNode head) {
if (head==null) return null;
RandomListNode p = head;
while (p != null) {
RandomListNode newNode = new RandomListNode(p.label);
newNode.next = p.next;
p.next = newNode;
p = newNode.next;
}
p = head;
RandomListNode p2 = head.next;
RandomListNode newHead = p2;
while (p2.next != null) {
if (p.random==null) {
p2.random = null;
} else {
p2.random = p.random.next;
}
p.next = p2.next;
p = p.next;
p2.next = p.next;
p2 = p2.next;
}
p.next = null;
return newHead;
}
}
--------------------------------------------------
Submission Result: Wrong Answer
Input: {-1,-1}
Output: {-1,#}
Expected: {-1,-1}
不明白这个{-1,#}什么意思,但是本机测试可以通过-1,-1啊...
谢谢!