Skip to content

Bug Report for clone-graph #4661

@Greimil

Description

@Greimil

Bug Report for https://neetcode.io/problems/clone-graph

Looks like this problem for some reason can't be solved using c#, here is my solution: public class Solution {
public Node CloneGraph(Node node)
{
if (node == null) return null;

Dictionary<Node, Node> hashMap = new Dictionary<Node, Node>();

Node dfs(Node curr)
{
   
    if (hashMap.ContainsKey(curr))
        return hashMap[curr];

    
    Node clone = new Node(curr.val);
    hashMap[curr] = clone;

    
    foreach (Node neighbor in curr.neighbors)
    {
        clone.neighbors.Add(dfs(neighbor));
    }

    return clone;
}

return dfs(node);

}
}

Also here's an screenshop:

Image

Note: I tried copying the solution but did not work anyway.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions