Runtime error. Last input executed {0, 0, 0} what does it mean and what's wrong?


  • 0
    S

    Based on the explanation about how the graph is formed, I assumed that {0,0,0} represent the following Object:

      label: 0,
      neighbors: [
        {
          label: 0,
          neighbors: [
          ]
        },
        {
          label: 0,
          neighbors: [
          ]
        },
      ]
    

    The following does clone the graph correctly, however, I am getting this error:
    Runtime Error. Last Input executed {0, 0, 0} what does it mean? any clue?

    function UndirectedGraphNode(label) {
        this.label = label;
        this.neighbors = [];   // Array of UndirectedGraphNode
    }
    
    var cloneGraph = function(graph) {
        if (graph === null || Object.keys(graph).length === 0) return {};
        var newCloneGraph;
        function cloning(graph, newCloneGraph) {
            newCloneGraph = newCloneGraph || new UndirectedGraphNode(graph.label);
            if (graph.neighbors.length > 0) {
                var newNode;
                for ( var i=0; i<graph.neighbors.length; i++) {
                    newNode = new UndirectedGraphNode(graph.neighbors[i].label);
                    newCloneGraph.neighbors.push(newNode);
                    cloning(graph.neighbors[i], newCloneGraph.neighbors[i]);
                }
            }
            return newCloneGraph;
        }
        return cloning(graph);
    };

Log in to reply
 

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