leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0690.cpp (693B)


      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 getImportance(const vector<Employee *> employees, int id) const {
     14         static const Employee *um[2001];
     15 
     16         memset(um, 0x00, sizeof(um));
     17         for (const Employee *employee : employees)
     18             um[employee->id] = employee;
     19 
     20         int res = 0;
     21         queue<int> q({id});
     22         while (!q.empty()) {
     23             int id = q.front();
     24             q.pop();
     25             res += um[id]->importance;
     26             for (const int sub : um[id]->subordinates)
     27                 q.push(sub);
     28         }
     29 
     30         return res;
     31     }
     32 };