算法分析与设计第十六周:582. kill process

来源:互联网 发布:sql查询前三条 编辑:程序博客网 时间:2024/06/15 08:53
class Solution(object):    def killProcess(self, pid, ppid, kill):        """        :type pid: List[int]        :type ppid: List[int]        :type kill: int        :rtype: List[int]        """        dict1 = {}        size = len(pid)        res = [kill]        for i in range(size):            if dict1.get(ppid[i]) == None:                dict1[ppid[i]] = [pid[i]]            else:                dict1[ppid[i]] += [pid[i]]        kill = [kill]        while kill != []:            tmp = kill[0]            if dict1.get(tmp) != None:                res += dict1[tmp]                kill += dict1[tmp]            del kill[0]        return res
原创粉丝点击