Python short & fast solution beats 100%


  • 0
    Y
    class Solution(object):
        def killProcess(self, pid, ppid, kill):
            """
            :type pid: List[int]
            :type ppid: List[int]
            :type kill: int
            :rtype: List[int]
            """
            child = collections.defaultdict(list)
            ret = []
            for c, p in zip(pid, ppid):
                child[p].append(c)
            stack = [kill]
            while stack:
                current = stack.pop()
                ret.append(current)
                stack += child[current]
            return ret
    

Log in to reply
 

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