```
private Set<UndirectedGraphNode> visited = new HashSet<>();
public UndirectedGraphNode cloneGraph(UndirectedGraphNode node) {
if(node == null){
return null;
}
UndirectedGraphNode clone = new UndirectedGraphNode(node.label);
visited.add(node);
for(int i = 0; i < node.neighbors.size(); i++){
UndirectedGraphNode neighbor = node.neighbors.get(i);
// only recurse once
if(!visited.contains(neighbor)){
clone.neighbors.add(cloneGraph(neighbor));
}else{
clone.neighbors.add(new UndirectedGraphNode(neighbor.label));
}
}
return clone;
}
```

The thoughts of this algorithm is to only start a new sub-call/recursion if a node is not visited yet, otherwise just make a new node and add to neighbors list.

The {0,0,0} test case results in {0,0,0#0#0} instead of {0,0,0}, I ran my code locally with {0,0,0} and it was able to print out correct results. Any help would be appreciated.