**
剑指offer35 复杂链表的复制
**
这道连题目都没看懂的题,确实有点难度。代码量并不是很大,但是回溯法的思路始终是没有掌握。直到码字的这一刻还是没有理解代码。之后需要重点回看
/*
// 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 {
public Map<Node, Node> table = new HashMap<Node, Node>();
public Node copyRandomList(Node head) {
if(head == null){
return null;
}
if(!table.containsKey(head)){
Node headNew = new Node(head.val);
table.put(head, headNew);
headNew.next = copyRandomList(head.next);
headNew.random = copyRandomList(head.random);
}
return table.get(head);
}
}