Python code that beats 100% of submissions


  • 0
    class Solution(object):
        def killProcess(self, pid, ppid, kill):
            """
            :type pid: List[int]
            :type ppid: List[int]
            :type kill: int
            :rtype: List[int]
            """
            relation = collections.defaultdict(list)
            result = [kill]
            for index,item in enumerate(ppid):
                relation[item].append(pid[index])
            
            def findChild(parent,relation,killList):
                childList = relation[parent]
                for child in childList:
                    killList += [child]
                    if child not in relation:
                        continue
                    killList = findChild(child,relation,killList)
                return killList
            
            killList = findChild(kill,relation,[kill])
            return killList

Log in to reply
 

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