If I make the map as private static, it fails, it seems a bug for leetcode

  • 0
    public Map<Integer,UndirectedGraphNode> map = new HashMap<>();
    public UndirectedGraphNode cloneGraph(UndirectedGraphNode node) {
            return null;
        if(map.containsKey(node.label)) {
            return map.get(node.label);
        UndirectedGraphNode cloned = new UndirectedGraphNode(node.label);
        map.put(cloned.label, cloned);
        for(UndirectedGraphNode neighbor:node.neighbors) {
        return cloned;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.