Skip to content

Commit 8496346

Browse files
refactor 138
1 parent d829efc commit 8496346

File tree

1 file changed

+10
-10
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+10
-10
lines changed

src/main/java/com/fishercoder/solutions/_138.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313

1414
public class _138 {
1515
public static class Solution1 {
16-
public RandomListNode copyRandomList(RandomListNode head) {
16+
public Node copyRandomList(Node head) {
1717
/**Key is the original nodes, value is the new nodes we're deep copying to.*/
18-
Map<RandomListNode, RandomListNode> map = new HashMap();
19-
RandomListNode node = head;
18+
Map<Node, Node> map = new HashMap();
19+
Node node = head;
2020

2121
//loop for the first time: copy the node themselves with only labels
2222
while (node != null) {
23-
map.put(node, new RandomListNode(node.label));
23+
map.put(node, new Node(node.val));
2424
node = node.next;
2525
}
2626

@@ -36,14 +36,14 @@ public RandomListNode copyRandomList(RandomListNode head) {
3636
}
3737

3838
// Definition for singly-linked list with a random pointer.
39-
class RandomListNode {
40-
int label;
39+
class Node {
40+
int val;
4141

42-
RandomListNode next;
43-
RandomListNode random;
42+
Node next;
43+
Node random;
4444

45-
RandomListNode(int x) {
46-
this.label = x;
45+
Node(int x) {
46+
this.val = x;
4747
}
4848
}
4949
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy