python - kill process


  • 0
    S
    class Solution(object):
        def killProcess(self, pid, ppid, kill):
            """
            :type pid: List[int]
            :type ppid: List[int]
            :type kill: int
            :rtype: List[int]
            """
            sched_tree = {}
            for i,parent in enumerate(ppid):
                if parent not in sched_tree:
                    sched_tree[parent] = []
                sched_tree[parent].append(pid[i])
            
            queue = [kill]
            answer = []
            while queue:
                curr = queue.pop(0)
                answer.append(curr)
                if curr in sched_tree:
                    queue += sched_tree[curr]
            
            return answer
    

Log in to reply
 

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