/**
 * Definition for undirected graph.
 * class UndirectedGraphNode {
 *     int label;
 *     List<UndirectedGraphNode> neighbors;
 *     UndirectedGraphNode(int x) { label = x; neighbors = new ArrayList<UndirectedGraphNode>(); }
 * };
 */
public class Solution {
    public UndirectedGraphNode cloneGraph(UndirectedGraphNode node) {
        if (node == null) {
            return null;
        }
        
        Queue<UndirectedGraphNode> queue = new LinkedList<UndirectedGraphNode>();
        UndirectedGraphNode newHead = new UndirectedGraphNode(node.label);
        Map<UndirectedGraphNode, UndirectedGraphNode> map = new HashMap<UndirectedGraphNode, UndirectedGraphNode>();
        map.put(node, newHead);
        queue.offer(node);
        while (queue.size() > 0) {
            UndirectedGraphNode curr = queue.poll();
            List<UndirectedGraphNode> currNeighbors = curr.neighbors;
            for (int i = 0; i < currNeighbors.size(); i++) {
                UndirectedGraphNode currCopy = map.get(curr);
                if (map.containsKey(currNeighbors.get(i)) == false) {
                    UndirectedGraphNode neighborCopy = new UndirectedGraphNode(currNeighbors.get(i).label);
                    currCopy.neighbors.add(neighborCopy);
                    map.put(currNeighbors.get(i), neighborCopy);
                    queue.offer(currNeighbors.get(i));
                } else {
                    currCopy.neighbors.add(map.get(currNeighbors.get(i)));
                }
            }
        }

        return newHead;
    }
}

@@ -1,10 +1,9 @@
 /*
-*%0A *
+%0A//
  Def
@@ -18,58 +18,30 @@
 for 
-undirected graph.%0A * class UndirectedGraph
+a Node.%0Aclass 
 Node %7B%0A 
 *   
@@ -40,52 +40,43 @@
  %7B%0A 
-*
    
- 
+public
  int 
-labe
+va
 l;%0A 
-*
    
-  List%3CUndirectedGraph
+public List%3C
 Node
@@ -92,54 +92,108 @@
 rs;%0A
- * 
+%0A
     
-UndirectedGraphNode(int x) %7B label = x;
+public Node() %7B%7D%0A%0A    public Node(int _val,List%3CNode%3E _neighbors) %7B%0A        val = _val;%0A       
  nei
@@ -205,65 +205,32 @@
 s = 
+_
 ne
-w ArrayList%3CUndirectedGraphNode%3E(); %7D%0A * 
+ighbors;%0A    %7D%0A
 %7D;%0A
- 
 */%0A
-public 
 clas
@@ -253,31 +253,16 @@
  public 
-UndirectedGraph
 Node clo
@@ -269,31 +269,16 @@
 neGraph(
-UndirectedGraph
 Node nod
@@ -294,101 +294,61 @@
     
-if (node == null) %7B%0A            return null;%0A        %7D%0A        %0A        Queue%3CUndirectedGraph
+Map%3CNode, Node%3E map = new HashMap%3C%3E();%0A        Queue%3C
 Node
@@ -372,37 +372,45 @@
 kedList%3C
-UndirectedGraphN
+%3E();%0A        queue.offer(n
 ode
-%3E(
 );%0A     
@@ -416,192 +416,221 @@
     
-UndirectedGraphNode newHead = new UndirectedGraphNode(node.label);%0A        Map%3CUndirectedGraphNode, UndirectedGraphNode%3E map = new HashMap%3CUndirectedGraphNode, UndirectedGraphNode
+%0A        while (!queue.isEmpty()) %7B%0A            Node topNode = queue.poll();%0A            %0A            if (!map.containsKey(topNode)) %7B%0A                Node copy = new Node(topNode.val, new ArrayList%3C
 %3E()
+)
 ;%0A
+        
     
@@ -645,21 +645,21 @@
 put(
-n
+topN
 ode, 
-newHead
+copy
 );%0A 
@@ -669,112 +669,66 @@
     
-queue.offer(node);%0A        while (queue.size() %3E 0) %7B%0A            UndirectedGraphNode curr = queue.poll(
+    %7D%0A            %0A            Node copy = map.get(topNode
 );%0A 
@@ -747,34 +747,15 @@
 ist%3C
-UndirectedGraph
 Node%3E 
-currN
+n
 eigh
@@ -761,20 +761,23 @@
 hbors = 
-curr
+topNode
 .neighbo
@@ -796,118 +796,47 @@
     
-for (int i = 0; i %3C currNeighbors.size(); i++) %7B%0A                UndirectedGraphNode currCopy = map.get(curr);
+%0A            for (Node n : neighbors) %7B
 %0A   
@@ -852,16 +852,17 @@
     if (
+!
 map.cont
@@ -873,270 +873,111 @@
 Key(
-currNeighbors.get(i)) == false) %7B%0A                    UndirectedGraphNode neighborCopy = new UndirectedGraphNode(currNeighbors.get(i).label);%0A                    currCopy.neighbors.add(neighborCopy);%0A                    map.put(currNeighbors.get(i), neighborCopy
+n)) %7B%0A                    Node c = new Node(n.val, new ArrayList%3C%3E());%0A                    map.put(n, c
 );%0A 
@@ -1007,36 +1007,17 @@
 e.offer(
-currNeighbors.get(i)
+n
 );%0A     
@@ -1032,22 +1032,26 @@
    %7D
- else %7B
 %0A      
+          %0A
     
@@ -1064,13 +1064,11 @@
     
-currC
+  c
 opy.
@@ -1093,28 +1093,9 @@
 get(
-currNeighbors.get(i)
+n
 ));%0A
@@ -1102,34 +1102,26 @@
             
-    %7D%0A    
+%7D%0A
         %7D%0A  
@@ -1126,18 +1126,16 @@
         
-%7D%0A
 %0A       
@@ -1146,15 +1146,21 @@
 urn 
-newHead
+map.get(node)
 ;%0A  

Update CloneGraph.java