/*
// 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) {
if(employees.size() < 1)
return 0;
unordered_map<int, Employee*> hp;
for(int i = 0; i < employees.size(); i++)
{
hp[employees[i]->id] = employees[i];
}
deque<Employee*>dq;
dq.push_back(hp[id]);
int sum = 0;
while(!dq.empty())
{
Employee* em = dq.front();
dq.pop_front();
sum += em->importance;
if(!(em->subordinates).empty())
{
vector<int> v1 = em->subordinates;
for(int i = 0; i < v1.size(); i++)
{
dq.push_back(hp[i]);
}
}
}
return sum;
}
};
leetcode员工的重要性
最新推荐文章于 2021-05-01 15:08:50 发布