-
Notifications
You must be signed in to change notification settings - Fork 266
Expand file tree
/
Copy path35.java
More file actions
60 lines (34 loc) · 766 Bytes
/
35.java
File metadata and controls
60 lines (34 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class Solution {
public Node copyRandomList(Node head) {
if(head==null)
{
return head;
}
Node p = head;
while(p!=null)
{
Node node = new Node(p.val);
node.next = p.next;
p.next = node;
p = p.next.next;
}
p = head;
while(p!=null&&p.next!=null)
{
if(p.random!=null)
{
p.next.random = p.random.next;
}
p = p.next.next;
}
Node x = head.next;
Node q = head;
while(q.next!=null)
{
Node t = q.next;
q.next = q.next.next;
q = t;
}
return x;
}
}