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 (val) and a list (neighbors) of its adjacent nodes.
class Node {
val: int
neighbors: Node[]
}
The graph is represented as an adjacency list where the index of the array represents the node value (1-indexed). For example, [[2,4],[1,3],[2,4],[1,3]] means:
Return the adjacency list of the cloned graph in the same format.
adjList = [[2, 4], [1, 3], [2, 4], [1, 3]][[2, 4], [1, 3], [2, 4], [1, 3]]adjList = [[]][[]]adjList = [][]The number of nodes in the graph is in the range [0, 100]1 <= Node.val <= 100Node.val is unique for each nodeThere are no repeated edges and no self-loops in the graphThe graph is connected and all nodes can be visited starting from the given nodeExpected time complexity: O(V + E)Run your code to see results
Use Cmd+Enter to run