public RandomListNode copyRandomList(RandomListNode head) {

    if (head == null) {
      return null;
    }

    RandomListNode newHead = new RandomListNode(head.label);
    RandomListNode rst = newHead;

    Map<RandomListNode, RandomListNode> map = new HashMap<RandomListNode, RandomListNode>();
    map.put(head, newHead);

    head = head.next;
    while (head != null) {
      RandomListNode newNode = new RandomListNode(head.label);
      newHead.next = newNode;
      newHead = newNode;

      map.put(head, newNode);

      head = head.next;
    }

    for (Entry<RandomListNode, RandomListNode> entry : map.entrySet()) {

      RandomListNode oldNode = entry.getKey();
      RandomListNode newNode = entry.getValue();

      newNode.random = map.get(oldNode.random);
    }

    return rst;
  }