分析:bfs
/*
// 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 sum = 0;
int getImportance(vector<Employee*> employees, int id) {
int index;
for(int i = 0; i < employees.size(); i ++){
if(employees[i] == nullptr){
return sum;
}
if(employees[i]->id == id){
sum += employees[i]->importance;
index = i;
}
}
for(int i = 0; i < employees[index]->subordinates.size(); i ++){
getImportance(employees, employees[index]->subordinates[i]);
}
return sum;
}
};