Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- // Definition for Employee.
- class Employee {
- public:
- int id;
- int importance;
- vector<int> subordinates;
- };
- */
- class Solution {
- public:
- int totalImportance = 0;
- unordered_map<int, Employee*> map;
- void checkEmployee(int id) {
- totalImportance += map[id]->importance;
- for(int x: map[id]->subordinates) {
- checkEmployee(x);
- }
- }
- int getImportance(vector<Employee*> employees, int id) {
- for(auto x: employees)
- map[x->id] = x;
- checkEmployee(id);
- return totalImportance;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement