@@ -0,0 +1,1515 @@
+// Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.%0A%0A%0A%0A/**%0A * Definition for undirected graph.%0A * class UndirectedGraphNode %7B%0A *     int label;%0A *     List%3CUndirectedGraphNode%3E neighbors;%0A *     UndirectedGraphNode(int x) %7B label = x; neighbors = new ArrayList%3CUndirectedGraphNode%3E(); %7D%0A * %7D;%0A */%0Apublic class Solution %7B%0A    public UndirectedGraphNode cloneGraph(UndirectedGraphNode node) %7B%0A %09%09if(node == null) return node;%0A%0A %09%09HashMap%3CUndirectedGraphNode, UndirectedGraphNode%3E map = new HashMap%3CUndirectedGraphNode, UndirectedGraphNode%3E();%0A%0A %09%09UndirectedGraphNode runner = node;%0A %09%09Queue%3CUndirectedGraphNode%3E queue = new LinkedList%3CUndirectedGraphNode%3E();%0A %09%09Set%3CUndirectedGraphNode%3E visited = new HashSet%3CUndirectedGraphNode%3E();%0A %09%09queue.add(node);%0A%0A %09%09while(!queue.isEmpty())%7B%0A %09%09%09UndirectedGraphNode current = queue.poll();%0A%0A %09%09%09if(current != null && !visited.contains(current))%7B%0A %09%09%09%09visited.add(current);%0A %09%09%09%09if(!map.containsKey(current))%7B%0A  %09    %09%09%09UndirectedGraphNode copy = new UndirectedGraphNode(current.label);%0A %09%09    %09%09map.put(current, copy);%0A %09%09%09%09%7D%0A%0A %09%09%09%09for(UndirectedGraphNode n : current.neighbors)%7B%0A %09%09%09%09    if(map.containsKey(n))%7B%0A %09%09%09%09        map.get(current).neighbors.add(map.get(n));%0A %09%09%09%09    %7Delse%7B%0A %09%09%09%09        UndirectedGraphNode copyN = new UndirectedGraphNode(n.label);%0A %09%09%09%09        map.put(n, copyN);%0A %09%09%09%09        map.get(current).neighbors.add(copyN);%0A %09%09%09%09    %7D%0A %09%09%09%09%09queue.add(n);%0A %09%09%09%09%7D%0A %09%09%09%7D%0A %09%09%7D  %0A%0A %09%09return map.get(node); %0A    %7D%0A%7D

add clone graph solution