Python solution fail on {0,1#1,2#2,2}


  • 0
    R

    Leetcode claimed that output is {0,1#1}, but the output is {0,1#1,2#2,2} in my local laptop.

    built_nodes = {}
    def cloneGraph(self, node):
            if not node:
                return None
            that = UndirectedGraphNode(node.label)
            that.neighbors = [(self.cloneGraph(n) if n.label not in self.built_nodes else self.built_nodes[n.label])
                              if n.label != node.label else that for n in node.neighbors]
    
        self.built_nodes[node.label] = that
        return that

Log in to reply
 

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