690. Employee Importance - LeetCode
Question
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的更多相关文章
- (BFS) leetcode 690. Employee Importance
690. Employee Importance Easy 377369FavoriteShare You are given a data structure of employee informa ...
- LN : leetcode 690 Employee Importance
lc 690 Employee Importance 690 Employee Importance You are given a data structure of employee inform ...
- 【Leetcode_easy】690. Employee Importance
problem 690. Employee Importance 题意:所有下属和自己的重要度之和,所有下属包括下属的下属即直接下属和间接下属. solution:DFS; /* // Employe ...
- LeetCode 690. Employee Importance (职员的重要值)
You are given a data structure of employee information, which includes the employee's unique id, his ...
- 【LeetCode】690. Employee Importance 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:DFS 日期 题目地址:https://le ...
- LeetCode - 690. Employee Importance
You are given a data structure of employee information, which includes the employee's unique id, his ...
- LeetCode 690 Employee Importance 解题报告
题目要求 You are given a data structure of employee information, which includes the employee's unique id ...
- [LeetCode&Python] Problem 690. Employee Importance
You are given a data structure of employee information, which includes the employee's unique id, his ...
- leetcode 690. Employee Importance——本质上就是tree的DFS和BFS
You are given a data structure of employee information, which includes the employee's unique id, his ...
随机推荐
- servlet中的HttpServletRequest对象
HttpServletRequest对象表示客户端浏览器发起的请求,当客户端浏览器通过HTTP协议访问服务器时,Tomcat会将HTTP请求中的所有信息解析并封装在HttpServletRequest ...
- Python模块导入方式
import导入方式 from...import导入方式 from...import... 导入模块相当于在此文件中写了所导入函数名(对比c/c++中的.h文件来理解),所以在之后使用导入的函数直接 ...
- APICloud Github 5大开源项目集合展示
APICloud自成立之初,一直秉承着开源一切的初心,为了给予广大开发者们更多的资源及内容.不知不觉,2年时间已过,APICloud的github上已经集合了APICloud模块.前端框架及文档.云A ...
- 小程序开发之一(使用fly进行http封装)
原文地址:http://callmesoul.cn 下载fly js文件 fly小程序文档 /api/config.js 配置,主要配置全局的host url和request拦截和request拦截 ...
- 用Node处理文件上传
前言 在Web开发中,文件上传是一个非常常见.非常重要的功能.本文将介绍如何用Node处理上传的文件. 需求分析 由于现在前后端分离很流行,那么本文也直接采用前后端分离的做法.前端界面如下: 用户从浏 ...
- hive启动出错
Hive启动报错:java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument - 狗子的进阶史 - ...
- 【uniapp 开发】校验工具类 CheckUtil
校验手机号格式 /** * 验证是否为电话号码(座机) * * @param {} * source */ function isTelephone(source) { var regex = /^( ...
- Android 动态控制OptionMenu的显示与隐藏
在有些场景下,可能需要动态的显示和隐藏optionmenu,可以这样实现:如果在activity中默认实现了方法: onCreateOptionsMenu(Menu menu) 那么该OptionMe ...
- TINY语言采用递归下降分析法编写语法分析程序
目录 自顶向下分析方法 TINY文法 消左提左.构造first follow 基本思想 python构造源码 运行结果 参考来源:聊聊编译原理(二) - 语法分析 自顶向下分析方法 自顶向下分析方法: ...
- 7.Jenkins进阶之流水线pipeline语法入门学习(2)
目录一览: (2) Declarative Pipeline Syntax 2.1) Sections - 章节 2.2) Directives - 指令 2.3) Sequential Stages ...