Employee Importance

2017/12/8 posted in  leetcode

/*
// 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;
    }
};