@@ -0,0 +1,1593 @@
+package com.flang.clone;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0Apublic class CloneGraph %7B%0A%0A    public Node cloneGraph(Node node) %7B%0A        if (node == null) return null;%0A        // use the value of original node as key, map to the new copy node%0A        Map%3CInteger, Node%3E map = new HashMap();%0A        return copyGraph(node, map);%0A    %7D%0A%0A    private Node copyGraph(Node node, Map%3CInteger, Node%3E map) %7B%0A        if (map.get(node.val) != null) return map.get(node.val);%0A        // if we don't find the key in map, that tells us we don't have the copy node of that value in the map,%0A        // so we need create one%0A        Node copy = new Node(node.val);%0A        map.put(node.val, copy);%0A        for (Node neighbor : node.neighbors) %7B%0A            // we have the copy node, so we need make sure we have the same connection and have access to our%0A            // neighbors using copy.neighbors, and we have to add in the recursive call of copyGrpah because%0A            // copyGrpah always return clone graph%0A            copy.neighbors.add(copyGraph(neighbor, map));%0A        %7D%0A        return copy;%0A    %7D%0A%0A    class Node %7B%0A        public int val;%0A        public List%3CNode%3E neighbors;%0A%0A        public Node() %7B%0A            val = 0;%0A            neighbors = new ArrayList%3CNode%3E();%0A        %7D%0A%0A        public Node(int _val) %7B%0A            val = _val;%0A            neighbors = new ArrayList%3CNode%3E();%0A        %7D%0A%0A        public Node(int _val, ArrayList%3CNode%3E _neighbors) %7B%0A            val = _val;%0A            neighbors = _neighbors;%0A        %7D%0A    %7D%0A%7D%0A

Create CloneGraph.java