C++ Solution Using Map and Recursion

  • 0
    class Solution {
        int TotalImportance(unordered_map<int, Employee*> & m, int id) {
            Employee * e = m[id];
            int total = e->importance;
            for (int sid: e->subordinates) total += TotalImportance(m, sid);
            return total;
        int getImportance(vector<Employee*> employees, int id) {
            unordered_map<int, Employee*> m;
            for (auto e: employees) m[e->id] = e;
            return TotalImportance(m, id);

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.