/*
// 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<int> subordinates;
};
*/
class Solution {
public:
int getImportance(vector<Employee*> employees, int id) {
unordered_map<int,Employee*> map;
for(int i=0;i<employees.size();i++){
map[employees[i]->id]=employees[i]; //employees不一定是有序排列
}
queue<int> q;
q.push(id);
int res=0;
while(!q.empty()){
int cur=q.front();
q.pop();
res+=map[cur]->importance;
for(int i=0;i<map[cur]->subordinates.size();i++){
q.push(map[cur]->subordinates[i]);
}
}
return res;
}
};
690. Employee Importance
最新推荐文章于 2021-12-30 12:17:21 发布