Loading content...
You are given a reference to a node in a connected undirected network. Your task is to create and return a deep copy (complete clone) of the entire network structure.
The network is represented as a graph where each node contains:
val)neighbors)A deep copy means that the cloned network must consist of entirely new node objects. No node in the cloned network should share memory references with any node in the original network. The structure, values, and neighbor relationships must be exactly preserved in the clone.
Input Format:
For simplicity, each node's value equals its 1-indexed position in the network (first node has val = 1, second has val = 2, etc.). The network is provided as an adjacency list where each index i contains a list of neighbor values for node i+1.
Output Format: Return the cloned node corresponding to the input node. The testing system will verify that your returned network is a valid deep copy with identical structure to the original.
adjList = [[2,4],[1,3],[2,4],[1,3]][[2,4],[1,3],[2,4],[1,3]]The network contains 4 nodes forming a cycle:
adjList = [[]][[]]The network contains a single isolated node with val=1 and no connections to other nodes. The deep copy is a new node with the same value and empty neighbor list.
adjList = [][]An empty adjacency list means there are no nodes in the network. The input node is null, so the output should also be null (represented as an empty list).
Constraints