/*
// 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(auto emp:employees){
map[emp->id] = emp;
}
return help(map,id);
}
int help(unordered_map<int, Employee*>& map, int id){
int sum = map[id]->importance;
for(auto element : map[id]->subordinates){
sum += help(map, element);
}
return sum;
}
};
Employee Importance
Copyright © 2017 Powered by LZH, Theme used GitHub CSS.