582 Kill Process
Input:
pid = [1, 3, 10, 5]
ppid = [3, 0, 5, 3]
kill = 5
Output:
[5,10]
Explanation:
3
/ \
1 5
/
10
Kill 5 will also kill 10.Last updated
Input:
pid = [1, 3, 10, 5]
ppid = [3, 0, 5, 3]
kill = 5
Output:
[5,10]
Explanation:
3
/ \
1 5
/
10
Kill 5 will also kill 10.Last updated
import collections
class Solution:
def killProcess(self, pid, ppid, kill):
"""
:type pid: List[int]
:type ppid: List[int]
:type kill: int
:rtype: List[int]
"""
g = collections.defaultdict(set)
for ppid, pid in zip(ppid, pid):
g[ppid].add(pid)
killed = []
def dfs(root):
killed.append(root)
for child in g[root]:
dfs(child)
dfs(kill)
return killed