Python DFS

  • 0
    class Solution:
        def connect(self, root):
            dic = {}
            def dfs(r, dep):
                if not r:
                if dep in dic:
                    dic[dep].next = r
       = None
                dic[dep] = r
                dfs(r.left, dep + 1)
                dfs(r.right, dep + 1)
            dfs(root, 0)

Log in to reply

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