【Leetcode_easy】690. Employee Importance
problem
题意:所有下属和自己的重要度之和,所有下属包括下属的下属即直接下属和间接下属。
solution:DFS;
/*
// Employee info
class Employee {
public:
// It's the unique ID of each node.
// unique id of this employee
int id;
// the importance value of this employee
int importance;
// the id of direct subordinates
vector<int> subordinates;
};
*/
class Solution {
public:
int getImportance(vector<Employee*> employees, int id) {
unordered_map<int, Employee*> mymap;//err.
for(auto employee:employees) mymap[employee->id] = employee;
return helper(id, mymap);
}
int helper(int id, unordered_map<int, Employee*> m) {
int res = m[id]->importance;
for(auto num:m[id]->subordinates)//err.
{
res += helper(num, m);
}
return res;
}
};
solution:BFS;
完
【Leetcode_easy】690. Employee Importance的更多相关文章
- 【LeetCode】690. Employee Importance 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:DFS 日期 题目地址:https://le ...
- (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 ...
- 690. Employee Importance - LeetCode
Question 690. Employee Importance Example 1: Input: [[1, 5, [2, 3]], [2, 3, []], [3, 3, []]], 1 Outp ...
- 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 ...
- 690. Employee Importance
好几种写法,这里贴几个出来 第一种:暴力解法,除去递归栈,空间复杂度O(1).时间复杂度略高 /* // Employee info class Employee { public: // It's ...
- 690. Employee Importance员工权限重要性
[抄题]: You are given a data structure of employee information, which includes the employee's unique i ...
随机推荐
- docker学习(五)
一.实战案例介绍一些典型的应用场景和案例. 1.使用Supervisor来管理进程Docker 容器在启动的时候开启单个进程,比如,一个 ssh 或者 apache 的 daemon 服务.但我们经常 ...
- C# 通过 参数返回 C++ 指针
参数返回 C++ 指针 C++ 代码 Extern_C BASECORELIBRARY_API char * GetFileByteArray(wchar_t * BinfilePath, wchar ...
- sql server 综合使用的例子
exec sp_helptext prosampleoldstyle_usp -- ============================================= -- ========= ...
- Vue中使用matomo进行访问流量统计的实现
Vue中使用matomo进行访问流量统计 原文链接 前言 之前做到了一个页面及接口访问流量统计的需求, 然后在网上找了很多帖子,发现有些有的但是写的都不是很详细,所以今天就整理了一下 正文 第一步 首 ...
- 打造简单OS-总目录
1-汇编写入引导区,虚拟机启动步骤 (了解即可) 2-开机BIOS初始化与MBR操作系统引导详解 (了解即可) 3-MBR引导区转移加载简单程序(突破512限制)(了解即可) 4-loader硬盘加载 ...
- 怎么写一个带 bin 的 npm 包
只需要2步: 1. 在package.json 定义 一下 : { "name": "my-cli", ..., "bin": { &quo ...
- ios兼容
border-radius在ios的兼容:-webkit-appearance:none; 加上这个属性,可以保证安卓和ios的圆角一致 上传图片,这段没有代码没有管图片拍摄的方位, var _th ...
- Java学习日记基础篇(四)——类,对象之成员变量,成员方法,构造方法
面向对象(Object Oriented) 一.面向对象杂谈 面向对象(Object Oriented),我的翻译是以物体为目标的,就是说编程的时候是建立一个物体,然后对这个物体进行操作. Java语 ...
- create an oauth app
github可以对自己的服务进行oauth认证,创建oauth认证的方式如下: github -> Settings -> Developer settings -> Develop ...
- maven引入第三方jar包
maven有两种文件解析和分配策略,也就是我们常说的artifacts(依赖). 第一种是本地仓库,这是你缓存在本地的依赖.默认在${user.home}/.m2/repository目录下;当mav ...