Question

690. Employee Importance

Example 1:

Input: [[1, 5, [2, 3]], [2, 3, []], [3, 3, []]], 1
Output: 11
Explanation:
Employee 1 has importance value 5, and he has two direct subordinates: employee 2 and employee 3. They both have importance value 3. So the total importance value of employee 1 is 5 + 3 + 3 = 11.

Solution

题目大意:

每个员工都有一个价值,求一个员工及其下属员工价值总和

思路:

构造一个map来映射每个员工id和员工详细信息,再构造一个队列来遍历员工数据

Java实现:

public int getImportance(List<Employee> employees, int id) {
Map<Integer, Employee> employeeMap = new HashMap<>();
for (Employee tmp : employees) {
employeeMap.put(tmp.id, tmp);
} Queue<Employee> employeeQueue = new LinkedList<>();
employeeQueue.offer(employeeMap.get(id));
int importance = 0;
while (!employeeQueue.isEmpty()) {
Employee cur = employeeQueue.poll();
importance += cur.importance;
if (cur.subordinates == null) continue;
for (int tmp : cur.subordinates) {
employeeQueue.offer(employeeMap.get(tmp));
}
}
return importance;
}

690. Employee Importance - LeetCode的更多相关文章

  1. (BFS) leetcode 690. Employee Importance

    690. Employee Importance Easy 377369FavoriteShare You are given a data structure of employee informa ...

  2. LN : leetcode 690 Employee Importance

    lc 690 Employee Importance 690 Employee Importance You are given a data structure of employee inform ...

  3. 【Leetcode_easy】690. Employee Importance

    problem 690. Employee Importance 题意:所有下属和自己的重要度之和,所有下属包括下属的下属即直接下属和间接下属. solution:DFS; /* // Employe ...

  4. LeetCode 690. Employee Importance (职员的重要值)

    You are given a data structure of employee information, which includes the employee's unique id, his ...

  5. 【LeetCode】690. Employee Importance 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:DFS 日期 题目地址:https://le ...

  6. LeetCode - 690. Employee Importance

    You are given a data structure of employee information, which includes the employee's unique id, his ...

  7. LeetCode 690 Employee Importance 解题报告

    题目要求 You are given a data structure of employee information, which includes the employee's unique id ...

  8. [LeetCode&Python] Problem 690. Employee Importance

    You are given a data structure of employee information, which includes the employee's unique id, his ...

  9. leetcode 690. Employee Importance——本质上就是tree的DFS和BFS

    You are given a data structure of employee information, which includes the employee's unique id, his ...

随机推荐

  1. vulnhub 靶机 Kioptrix Level 1渗透笔记

    靶机下载地址:https://www.vulnhub.com/entry/kioptrix-level-1-1,22/ kali ip 信息收集 先使用nmap收集目标的ip地址 nmap -sP 1 ...

  2. ubuntu sublime text3 python 配置 sublime text3 python 配置

    ubuntu sublime text3 python 配置     1.安装sublime text 3 安装过程非常简单,在terminal中输入: sudo add-apt-repository ...

  3. Linux套接子(c语言)模拟http请求、应答

    有关套接子和http请求报文的博客在CSDN有很多比如,点这里查看,这里我就不再做过多赘述了,下面我们直接实战,模拟http请求. 要求:浏览器访问本地的localhost,在浏览器页面打印出 Hel ...

  4. 微信小程序:自定义组件的数据传递

    一.前言 如果小程序中有可复用的UI且具有一定的功能性,就可以使用自定义组件将其封装起来.下面介绍一个简单的组件和一个复杂的组件. 二.简单的组件(计数器) 1. 组件功能介绍 这个组件常见于外卖软件 ...

  5. JavaScript 工作原理之六-WebAssembly 对比 JavaScript 及其使用场景

    原文请查阅这里,略有改动,本文采用知识共享署名 4.0 国际许可协议共享,BY Troland. 本系列持续更新中,Github 地址请查阅这里. 这是 JavaScript 工作原理的第六章. 现在 ...

  6. sparksql Seq生成DataFrame

    首先,使用样例类: case class User(id:Int,name: String,gender:String, age: Int) 之后使用Seq创建Dataframe val alice: ...

  7. echarts中boundaryGap属性

    boundaryGap:false boundaryGap:true 代码处: xAxis: { type: "category", data: ["06-01" ...

  8. php实验一专属跳转博文

    今天完成了php关于设计个人博客主页的实验一作业. 这是php实验一作业中博客的跳转链接页.  

  9. Vue+element搭建后台管理系统-二、安装插件

    我们继续上一章的内容,上一章讲到我们已经能将项目成功跑起来了,那么我们接下来把项目必用的东西完善一下. 一.安装elementUI 终于到了我们的男二了,继续在VSCode中新建一个终端,然后通过这个 ...

  10. 初踩坑JS加载与audio接口:点击头像开始/暂停背景音乐

    背景 封楼期间难得空闲,也静不下心学习,空闲之余萌生了重做引导单页的想法.因为之前都是扒站(某大公司游戏官网)+小改,一来虽然很炫酷,但本人水平有限,仍有很大一部分JS无从下手,甚至是看不懂|-_-| ...