C++ Unordered_map


  • 0
    D
        vector<int> killProcess(vector<int>& pid, vector<int>& ppid, int kill) 
        {
            unordered_multimap<int,int> tm;
            vector<int> res(1,kill);     //add the kill process to result
            int n=ppid.size(),i=0;
            for(int i=0;i<n;i++)     //insert all data into map
                tm.insert(make_pair(ppid[i],pid[i]));
            while(i!=res.size()) 
            {
                auto range=tm.equal_range(res[i]);
                for(auto it=range.first;it!=range.second;it++)
                    res.push_back((*it).second);
                i++;
            }
            return res;
        }
    

Log in to reply
 

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