Java Solution


  • 0
    C
    public List<Integer> killProcess(List<Integer> pid, List<Integer> ppid, int kill) {
            if(kill == 0){
                return ppid;
            }
            
            Map<Integer, List<Integer>> map = new HashMap<>();
            for(int i=0; i<ppid.size(); i++){
                map.computeIfAbsent(ppid.get(i), k -> new ArrayList<Integer>()).add(pid.get(i));
            }
            
            List<Integer> result = new ArrayList<>();
            
            List<Integer> list1 = Arrays.asList(kill);
            while(!list1.isEmpty()){
                List<Integer> list2 = new ArrayList<>();
                for(int n : list1){
                    result.add(n);
                    list2.addAll(map.getOrDefault(n, new ArrayList<Integer>()));
                }
                
                list1 = list2;
            }
            
            return result;
        }
    

Log in to reply
 

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