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

class Solution {
    HashMap<Node,Node> map = new HashMap<>();
    public Node copyRandomList(Node head) {
        if(head == null) return null;
        Node p = head;
        while(p!=null){
            Node q = new Node(p.val);
            map.put(p,q);
            p = p.next;
        }
        p = head;
        while (p!=null){
            Node q = map.get(p);
            if(p.next!=null){
                q.next = map.get(p.next);
            }
            if(p.random!=null){
                q.random = map.get(p.random);
            }
            p = p.next;
        }
        return map.get(head);
    }
}

我的前方是万里征途,星辰大海!!
原文地址:https://www.cnblogs.com/taoyuxin/p/13529852.html