Clone Graph

Given a reference of a node in a connected undirected graph, return a deep copy (clone) of the graph. Each node in the graph contains a value and a list of its neighbors. The graph is represented using an adjacency list, and you must return the copy of the given node as a reference to the cloned graph.

Constraints

  • The number of nodes in the graph is in the range [0, 100].
  • 1 <= Node.val <= 100
  • Node.val is unique for each node.
  • There are no repeated edges and no self-loops in the graph.
  • The Graph is connected and all nodes can be visited starting from the given node.
Saving… · 2 lines
class Solution:
def cloneGraph(self, node: 'Node') -> 'Node':
Console

Click Run to execute sample tests.