JavaScript: Input: {-1,1#1} Output: {-1} Expected: {-1,1#1}


  • 0
    var map = {};
    
    var cloneGraph = function(graph) {
    	return cloneNode(graph);
    };
    
    var cloneNode = function(target) {
    	if (target === null) {
    		return null;
    	}
    	if (map[target.label] !== undefined) {
    		return map[target.label];
    	}
    	var node = new UndirectedGraphNode(target.label);
    	map[target.label] = node;
    	for (var i = 0; i < target.neighbors.length; i++) {
    		node.neighbors.push(cloneNode(target.neighbors[i]));
    	}
    	return node;
    }
    

    More Details

    Input: {-1,1#1}

    Output: {-1}

    Expected: {-1,1#1}


Log in to reply
 

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