c++ hash BFS


  • 0
    D

    '''
    class Solution {
    public:
    vector<int> res;
    vector<int> killProcess(vector<int>& pid, vector<int>& ppid, int kill) {
    int len = pid.size();
    unordered_map<int, vector<int>> m;
    int t;

        for (int i = 0; i < len; i++)
        {
            m[ppid[i]].push_back(pid[i]);
        }
        queue<int> q;
        q.push(kill);
        while (!q.empty())
        {
            int len1 = q.size();
            for (int i = 0; i < len1; i++)
            {
                t = q.front();
                res.push_back(t);
                q.pop();
                if (!m[t].empty())
                {
                    for (int j = 0; j < m[t].size(); j++)
                    {
                        q.push(m[t][j]);
                    }
                }
            }
        }
        return res;
    }
    

    };
    '''


Log in to reply
 

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