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. They have importance value 15, 10 and 5, respectively. Then employee 1 has a data structure like [1, 15, [2]], and employee 2 has [2, 10, [3]], and employee 3 has [3, 5, []]. Note that although employee 3 is also a subordinate of employee 1, the relationship is not direct.
Now given the employee information of a company, and an employee id, you need to return the total importance value of this employee and all his subordinates.
思路:
根据给出的领导id,在员工集合中找到该领导,并把其所有的直系下属找出来,直系下属再通过调用同一个函数来寻找直系下属,并把重要值进行相加。
class Solution {public int getImportance(List<Employee> employees, int id) {int importance = 0;List<Integer> subordinates = new ArrayList<Integer>();for(Employee e : employees){if(e.id == id){importance = e.importance;subordinates = e.subordinates;for(Integer i : subordinates)importance = importance + getImportance(employees,i);break;}}return importance;}
}
690. Employee Importance相关推荐
- Leetcode690.Employee Importance员工的重要性
给定一个保存员工信息的数据结构,它包含了员工唯一的id,重要度 和 直系下属的id. 比如,员工1是员工2的领导,员工2是员工3的领导.他们相应的重要度为15, 10, 5.那么员工1的数据结构是[1 ...
- Depth-first Search深度优先搜索专题1
104. Maximum Depth of Binary Tree 思路:顺着树的一个分支一直数层数直到叶子节点.DFS的思路.这个题目可以练习的是递归转迭代. 代码 695. Max Area of ...
- LeetCode github集合,附CMU大神整理笔记
Github LeetCode集合 本人所有做过的题目都写在一个java项目中,同步到github中了,算是见证自己的进步.github目前同步的题目是2020-09-17日之后写的题.之前写过的题会 ...
- Leetcode算法题-解法转载
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/fuxuemingzhu/article/details/85112591 作者: 负雪明烛 i ...
- LeetCode All in One 题目讲解汇总(持续更新中...)
原文地址:https://www.cnblogs.com/grandyang/p/4606334.html 终于将LeetCode的大部分题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开 ...
- Leetcode 690
问题描述:简单型,BFS解法 You are given a data structure of employee information, which includes the employee's ...
- 【LeetCode】深搜DFS(共85题)
[98]Validate Binary Search Tree [99]Recover Binary Search Tree [100]Same Tree [101]Symmetric Tree [1 ...
- LeetCode 力扣算法题解汇总,All in One
作者: 负雪明烛 id: fuxuemingzhu 个人博客: https://fuxuemingzhu.cn 关键词:LeetCode,力扣,算法,题解,汇总,解析 把自己刷过的所有题目做一个整理, ...
- Java算法:LeetCode算法Java版合集513-1110题
513. 找树左下角的值 题目描述 给定一个二叉树,在树的最后一行找到最左边的值. 示例 1: 输入:2/ \1 3 输出: 1 示例 2: 输入:1/ \2 3/ / \4 5 6/7 输出: 7 ...
最新文章
- 安徽自考计算机基础考试时间,安徽2021年4月自考考试时间
- java中tomcat检测_eclipse+tomcat测试JSP
- wpf学习笔记---初识xaml标签语言
- 数据结构 - 赫夫曼树
- IOS代理的设计模式
- MDT 2013 从入门到精通之自动化部署WinSer 2012 R2
- C#网络编程示例(note)
- python中tqdm的用法
- linux文件夹同步-文件对比工具,FreeFileSync,文件/文件夹比较和自动同步软件
- 数据库设计及案例分析
- idea :插件Statistic 统计代码数量和行数
- buuctf misc部分wp
- php文件如何转换成mp4,qlv文件如何转换成mp4 怎样把下载好的qlv格式视频转换成MP4格式...
- Windows服务器无法配置IP
- 容器中的 Shim 到底是个什么鬼?
- 整车nvh培训入门 仿真 ,基于Hyperworks 掌握思路 细节
- Android 8,Android开发经典实战
- Spring框架究竟是什么
- java程序内存占用过高问题排查
- MySQL 8.0.16安装教程(windows 64位)
热门文章
- 微信小程序 帮你算月供
- argparse用于解析命令行参数
- 《数值分析(原书第2版)》—— 导读
- python实训总结泰坦尼克号_Python-数据清洗与分析案例之泰坦尼克号(一)
- Chrony与NTP对比
- [程序员学英语]英语国际音标
- C Prime Plus 第二章 C语言概述
- PatterNodes for Mac(创建图形矢量模式工具)
- python进入目录 cd_Linux cd命令:切换目录
- linux解压安装包失败了怎么办,解压文件出错怎么办?百度网盘、Winrar等解压文件出错解决办法...