We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 46ff512 commit 274711eCopy full SHA for 274711e
java/138-Copy-List-with-Random-Pointer.java
@@ -0,0 +1,17 @@
1
+class Solution {
2
+ public Node copyRandomList(Node head) {
3
+ Node cur = head;
4
+ HashMap<Node, Node> map = new HashMap<>();
5
+ while (cur!=null) {
6
+ map.put(cur, new Node(cur.val));
7
+ cur = cur.next;
8
+ }
9
+ cur = head;
10
11
+ map.get(cur).next = map.get(cur.next);
12
+ map.get(cur).random = map.get(cur.random);
13
14
15
+ return map.get(head);
16
17
+}
0 commit comments