题目:给两个list,第一个代表pid,第二个代表ppid ,长度均为n,代表n个进程,eg :pid = [1,3,10,5],ppid = [3,0,5,3](1的父进程是3,3的父进程是0,10的父进程是5,5的父进程是3),杀死5,输出10 。。画出树状图如下 3
/
1 5
/
10
class Solution(object): def killProcess(self, pid, ppid, kill): """ :type pid: List[int] :type ppid: List[int] :type kill: int :rtype: List[int] """ d = collections.defaultdict(list); for c, p in zip(pid, ppid): d[p].append(c) bfs = [kill] for i in bfs: bfs.extend(d.get(i,[])) return bfs