✉️문제
https://leetcode.com/problems/clone-graph/description/
🗝 문제풀이
class Solution {
Node[] visited;
public Node cloneGraph(Node node) {
if(node == null) return null;
visited = new Node[101];
return recursive(node);
}
public Node recursive(Node node) {
if(visited[node.val] != null) return visited[node.val];
visited[node.val] = new Node(node.val);
for(Node n : node.neighbors) visited[node.val].neighbors.add(recursive(n));
return visited[node.val];
}
}