Clone Graph
Deep-copy the connected undirected graph reachable from node. Return a new entry node preserving labels and adjacency, with no original nodes reused. Input adjacency row i lists neighbors of label i+1; empty input represents null.
Example 1
node = [[2,3],[1,3],[1,2]][[2,3],[1,3],[1,2]]Explanation
Allocate three fresh nodes and reproduce the triangle's six adjacency entries.
Example 2
node = [[]][[]]Explanation
The isolated node still needs a fresh copy despite having no neighbors.
Example 3
node = []nullExplanation
A null graph copies to null rather than an isolated node.
Constraints
- 0 <= number of nodes <= 100
- Labels are 1..n
- Graph is connected, simple and undirected
Function contract
cloneGraphArguments: graphSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 33 cases, on your device.
[[2,3],[1,3],[1,2]]