6 lines in python


  • 2
    R
    class Solution:
        def cloneGraph(self, node):
            return self.dfs(node, {})
            
        def dfs(self, node, d):
            if not node: return None
            if node not in d:
                d[node] = UndirectedGraphNode(node.label)
                d[node].neighbors += [self.dfs(n, d) for n in node.neighbors]
            return d[node]
    

  • 0
    F

    beautiful solution


  • 0
    M
    This post is deleted!

Log in to reply
 

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