Skip to content

Latest commit

 

History

History
55 lines (42 loc) · 1.41 KB

_690. Employee Importance.md

File metadata and controls

55 lines (42 loc) · 1.41 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


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 %


Solutions

Java

/*
// 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;
    }
}