Submission Detail

22 / 22 test cases passed.
Status:

Accepted

Runtime: 29 ms
Memory Usage: 42.2 MB
Submitted: 13 hours, 25 minutes ago
loading
Runtime Error Message:
Last executed input:
Input:
Output:
Expected:

Accepted Solutions Runtime Distribution

25.0
27.5
30.0
15.0
17.5
20.0
22.5
32.5
35.0
37.5
5
10
15
20
25
30
35
40
java
You are here!
Your runtime beats 8.71 % of java submissions.
Runtime (ms)
Distribution (%)

25.0
27.5
30.0
15.0
17.5
20.0
22.5
32.5
35.0
37.5
10
20
30
40
Zoom area by dragging across this chart

Accepted Solutions Memory Distribution

40250
40500
40750
41000
41250
41500
41750
42000
42250
42500
42750
43000
2.5
5.0
7.5
10.0
12.5
15.0
java
You are here!
Your memory usage beats 51.72 % of java submissions.
Memory (KB)
Distribution (%)

40500
41000
41500
42000
42500
43000
5
10
15
Zoom area by dragging across this chart

Invite friends to challenge Clone Graph


Submitted Code: 13 hours, 25 minutes ago

Language: java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
// Definition for a Node.
class Node {
public int val;
public List<Node> neighbors;
public Node() {
val = 0;
neighbors = new ArrayList<Node>();
}
public Node(int _val) {
val = _val;
neighbors = new ArrayList<Node>();
}
public Node(int _val, ArrayList<Node> _neighbors) {
val = _val;
neighbors = _neighbors;
}
}
*/
class Solution {
public Node cloneGraph(Node node) {
if (node == null)
return null;
if (node.neighbors.size() == 0) {
Node new_node = new Node(node.val);
return new_node;
}
ArrayList<Node> queue_clones = new ArrayList<Node>();
ArrayList<Node> queue_orig = new ArrayList<Node>();
Node n = node;
queue_orig.add(node);
// build queue of original nodes
int ind = 0;
while (node != null && node.neighbors.size() != 0) {
for (int i = 0; i < node.neighbors.size(); i++) {
if (!queue_orig.contains(node.neighbors.get(i))) {
queue_orig.add(node.neighbors.get(i));
}
}
if (ind < queue_orig.size()-1)
node = queue_orig.get(++ind);
else
break;
}
// second queue of cloned nodes
for (int i = 0; i < queue_orig.size(); i++) {
Node orig = queue_orig.get(i);
Node clone = new Node(orig.val);
queue_clones.add(clone);
}
// set adjacency lists for clones
for (int i = 0; i < queue_orig.size(); i++) {
Node orig = queue_orig.get(i);
for (int j = 0; j < orig.neighbors.size(); j++) {
Node child = orig.neighbors.get(j);
for (int k = 0; k < queue_clones.size(); k++) {
if (child.val == queue_clones.get(k).val)
queue_clones.get(i).neighbors.add(queue_clones.get(k));
}
}
}
return queue_clones.get(0);
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX