首页 > 其他 > 详细

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

时间:2018-01-24 21:09:55      阅读:200      评论:0      收藏:0      [点我收藏+]

哈希表存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员工重要信息

原文:https://www.cnblogs.com/stAr-1/p/8343084.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!