133. Clone Graph
Last updated
Was this helpful?
Last updated
Was this helpful?
Given a reference of a node in a undirected graph, return a (clone) of the graph. Each node in the graph contains a val (int
) and a list (List[Node]
) of its neighbors.
Example:
Note:
The number of nodes will be between 1 and 100.
Since the graph is undirected, if node p has node q as neighbor, then node q must have node p as neighbor too.
You must return the copy of the given node as a reference to the cloned graph.
学习大神解法,使用DFS。
The undirected graph is a , which means no repeated edges and no self-loops in the graph.