# 剑指 Offer 35. 复杂链表的复制

-10000 <= Node.val <= 10000
Node.random 为空（null）或指向链表中的节点。

/*
// Definition for a Node.
class Node {
int val;
Node next;
Node random;

public Node(int val) {
this.val = val;
this.next = null;
this.random = null;
}
}
*/
class Solution {
}
while(curr != null){
Node copyNode = new Node(curr.val);
copyNode.next = curr.next;
curr.next = copyNode;
curr = copyNode.next;
}
while(curr != null && curr.next != null){
Node tempNode = curr.next;
if(curr.random != null){
tempNode.random = curr.random.next;
}else{
tempNode.random = null;
}
curr = curr.next.next;
}
Node result = new Node(0);
result.next = curr;
while(curr != null && curr.next != null){
origin.next = curr.next;
origin = origin.next;
curr.next = curr.next.next;
curr = curr.next;
}
return result.next;
}
}

/*
// Definition for a Node.
class Node {
int val;
Node next;
Node random;

public Node(int val) {
this.val = val;
this.next = null;
this.random = null;
}
}
*/
class Solution {
}
Map<Node, Node> map = new HashMap();
while(curr != null){
map.put(curr, new Node(curr.val));
curr = curr.next;
}
while(curr != null){
map.get(curr).next = map.get(curr.next);
map.get(curr).random = map.get(curr.random);
curr = curr.next;
}
}