Advertisement
nikunjsoni

690

Jun 22nd, 2021
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. /*
  2. // Definition for Employee.
  3. class Employee {
  4. public:
  5.     int id;
  6.     int importance;
  7.     vector<int> subordinates;
  8. };
  9. */
  10.  
  11. class Solution {
  12. public:
  13.     int totalImportance = 0;
  14.     unordered_map<int, Employee*> map;
  15.    
  16.     void checkEmployee(int id) {
  17.         totalImportance += map[id]->importance;
  18.         for(int x: map[id]->subordinates) {
  19.             checkEmployee(x);
  20.         }
  21.     }
  22.    
  23.     int getImportance(vector<Employee*> employees, int id) {
  24.         for(auto x: employees)
  25.             map[x->id] = x;
  26.    
  27.         checkEmployee(id);
  28.         return totalImportance;
  29.     }
  30. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement