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
算法分析与设计第十六周:582. kill process
最新推荐文章于 2023-02-19 09:45:16 发布