690. Employee Importance
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : July 02, 2024
Last updated : July 02, 2024
Related Topics : Array, Hash Table, Tree, Depth-First Search, Breadth-First Search
Acceptance Rate : 67.56 %
/*
// Definition for Employee.
class Employee {
public int id;
public int importance;
public List<Integer> subordinates;
};
*/
class Solution {
public int getImportance(List<Employee> employees, int id) {
HashMap<Integer, Pair<Integer, List<Integer>>> hs = new HashMap<>();
for (Employee e : employees) {
hs.put(e.id, new Pair<Integer, List<Integer>>(e.importance, e.subordinates));
}
return helper(id, hs);
}
private int helper(int id, HashMap<Integer, Pair<Integer, List<Integer>>> data) {
int output = data.get(id).getKey();
for (Integer i : data.get(id).getValue()) {
output += helper(i, data);
}
return output;
}
}