690. Employee Importance

/*
// Employee info
class Employee {
public:
    // It's the unique ID of each node.
    // unique id of this employee
    int id;
    // the importance value of this employee
    int importance;
    // the id of direct subordinates
    vector subordinates;
};
*/
class Solution {
public:
    int getImportance(vector employees, int id) {
        unordered_map map;
        for(int i=0;iid]=employees[i]; //employees不一定是有序排列
        }
        queue q;
        q.push(id);
        int res=0;
        while(!q.empty()){
            int cur=q.front();
            q.pop();
            res+=map[cur]->importance;
            for(int i=0;isubordinates.size();i++){
                q.push(map[cur]->subordinates[i]);
            }     
        }
        return res;
    }
};

你可能感兴趣的:(Leetcode)