Python simple DFS

  • 0
    class Solution(object):
        def killProcess(self, pid, ppid, kill):
            if not pid or not ppid:
                return []
            adj = collections.defaultdict(list)
            for parent, child in zip(ppid, pid):
            ans = []
            self.dfs(kill, adj, ans)
            return ans
        def dfs(self, curr, adj, ans):
            for child in adj[curr]:
                self.dfs(child, adj, ans)

Log in to reply

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