[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;
    }

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

时间: 2024-08-01 02:10:08

[LeetCode]690. Employee Importance员工重要信息的相关文章

690. Employee Importance 员工重要性

You are given a data structure of employee information, which includes the employee's unique id, his importance value and his direct subordinates' id. For example, employee 1 is the leader of employee 2, and employee 2 is the leader of employee 3. Th

LeetCode - 690. Employee Importance

You are given a data structure of employee information, which includes the employee's unique id, his importance value and his directsubordinates' id. For example, employee 1 is the leader of employee 2, and employee 2 is the leader of employee 3. The

[LeetCode&amp;Python] Problem 690. Employee Importance

You are given a data structure of employee information, which includes the employee's unique id, his importance value and his direct subordinates' id. For example, employee 1 is the leader of employee 2, and employee 2 is the leader of employee 3. Th

【Breadth-first Search】690. Employee Importance(easy)

#week4# #from leetcode# Description You are given a data structure of employee information, which includes the employee's unique id, his importance value and his directsubordinates' id. For example, employee 1 is the leader of employee 2, and employe

[LeetCode] 690. Employee Importance_Easy tag: BFS

You are given a data structure of employee information, which includes the employee's unique id, his importance value and his directsubordinates' id. For example, employee 1 is the leader of employee 2, and employee 2 is the leader of employee 3. The

[LeetCode]577. Employee Bonus 员工奖金

Select all employee's name and bonus whose bonus is < 1000. Table:Employee +-------+--------+-----------+--------+ | empId | name | supervisor| salary | +-------+--------+-----------+--------+ | 1 | John | 3 | 1000 | | 2 | Dan | 3 | 2000 | | 3 | Brad

leetcode 690.员工的重要性

题目: 给定一个保存员工信息的数据结构,它包含了员工唯一的id,重要度 和 直系下属的id. 比如,员工1是员工2的领导,员工2是员工3的领导.他们相应的重要度为15, 10, 5.那么员工1的数据结构是[1, 15, [2]],员工2的数据结构是[2, 10, [3]],员工3的数据结构是[3, 5, []].注意虽然员工3也是员工1的一个下属,但是由于并不是直系下属,因此没有体现在员工1的数据结构中. 现在输入一个公司的所有员工信息,以及单个员工id,返回这个员工和他所有下属的重要度之和.

Leetcode 759. Employee Free Time

思路:区域覆盖问题.一个自然的想法是将每个员工的工作时间段看做一个木棒,每个木棒的长度就是这个时间段的时长.然后按照木棒的起始位置升序排列,接着由低位置向高位置一个木棒一个木棒的看过去.如果当前木棒的末节点的位置>下一个木棒的头节点位置,那么这两个节点就是一个free time的开头和结尾:如果当前木棒的末节点位置<=下一个木棒的头节点位置,那么更新当前木棒的末节点位置为max(当前木棒的末节点位置,下一个木棒的头节点位置). 1 /** 2 * Definition for an inter

算法与数据结构基础 - 广度优先搜索(BFS)

BFS基础 广度优先搜索(Breadth First Search)用于按离始节点距离.由近到远渐次访问图的节点,可视化BFS 通常使用队列(queue)结构模拟BFS过程,关于queue见:算法与数据结构基础 - 队列(Queue) 最直观的BFS应用是图和树的遍历,其中图常用邻接表或矩阵表示,例如 LeetCode题目 690. Employee Importance: // LeetCode 690. Employee Importance/* class Employee { publi