C++ 176ms Very Simple and Concise Solution

  • 0
    class Solution {
        vector<int> killProcess(vector<int>& pid, vector<int>& ppid, int kill) {
            unordered_map<int, vector<int>> childrens;
            for(int i=0; i<pid.size(); ++i){
            vector<int> killed{kill};
            int k = 0;
            while(k < killed.size()){
                // find the children pid
                auto iter = childrens.find(killed[k++]);
                if(iter != childrens.end()){
                    std::move(iter->second.begin(), iter->second.end(), std::back_inserter(killed));
            return killed;

Log in to reply

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