[LeetCode]690. Employee Importance员工重要信息

Posted stAr_1

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[LeetCode]690. Employee Importance员工重要信息相关的知识,希望对你有一定的参考价值。

哈希表存id和员工数据结构

递归获取信息

public int getImportance(List<Employee> employees, int id) {
        Map<Integer,Employee> map = new HashMap<>();
        for (int i = 0; i < employees.size(); i++) {
            Employee temp = employees.get(i);
            map.put(temp.id,temp);
        }
        return helper(map,id);
    }
    public int helper(Map<Integer,Employee> map, int id)
    {
        Employee cur = map.get(id);
        List<Integer> sub = cur.subordinates;
        int res = cur.importance;
        for (int i = 0; i < sub.size(); i++) {
            res += helper(map,sub.get(i));
        }
        return res;
    }

 

以上是关于[LeetCode]690. Employee Importance员工重要信息的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode - 690. Employee Importance

[LeetCode&Python] Problem 690. Employee Importance

[leetcode]Breadth-first Search-690. Employee Importance

[LeetCode] 690. Employee Importance_Easy tag: BFS

leetcode690

LeetCode690. 员工的重要性(BFS || DFS)