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的更多相关文章

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

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

  2. (BFS) leetcode 690. Employee Importance

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

  3. LN : leetcode 690 Employee Importance

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

  4. 690. Employee Importance - LeetCode

    Question 690. Employee Importance Example 1: Input: [[1, 5, [2, 3]], [2, 3, []], [3, 3, []]], 1 Outp ...

  5. LeetCode - 690. Employee Importance

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

  6. LeetCode 690 Employee Importance 解题报告

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

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

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

  8. 690. Employee Importance

    好几种写法,这里贴几个出来 第一种:暴力解法,除去递归栈,空间复杂度O(1).时间复杂度略高 /* // Employee info class Employee { public: // It's ...

  9. 690. Employee Importance员工权限重要性

    [抄题]: You are given a data structure of employee information, which includes the employee's unique i ...

随机推荐

  1. tomcat 处理HTTP请求

    一.Tomcat是什么?Tomcat是一个Web应用服务器,同时也是一个Servlet/JSP容器.Tomcat作为Servlet容器,负责处理客户端请求,把请求传送给Servlet,并将Servle ...

  2. struts2--CRUD

    struts的CRUD 1.导入相关的pom依赖(struts.自定义标签库的依赖) <dependency> <groupId>jstl</groupId> &l ...

  3. 【编程语言】Kotlin之扩展函数

    简介: 平时Android开发中会使用各种各样的工具类函数,大部分工具类都是对原有对象的一种扩展,例如: public static void startActivity(Activity act, ...

  4. 提高 github.com 项目下载速度

    1 注册一个 github.com 账号 2 进入你感兴趣的项目 3 Fork  一个副本到你的账号之下 4 git clone https://github.com/your-name/fork-p ...

  5. pandas 筛选某一列最大值最小值 sort_values、groupby、max、min

    高效方法: dfs[dfs['delta'].isnull()==False].sort_values(by='delta', ascending=True).groupby('Call_Number ...

  6. 数据结构实验之图论五:从起始点到目标点的最短步数(BFS)

    分析:有向图里面找最短路径,原理就是每一步都走距离自己最近的路, 一旦发现走一步可以到,那么这个一定是最短的. #include <bits/stdc++.h> using namespa ...

  7. [bzoj 4939][Ynoi 2016]掉进兔子洞

    传送门 Description 一个长为 n 的序列 a. 有 m 个询问,每次询问三个区间,把三个区间中同时出现的数一个一个删掉,问最后三个区间剩下的数的个数和,询问独立. 注意这里删掉指的是一个一 ...

  8. (转)awk 详解

    出处:https://blog.51cto.com/yijiu/1358416 awk详解 awk是一款非常牛逼的报告生成工具,能够将文本格式化成显示为比较直观的结果 废话不多说,直接上例子 awk的 ...

  9. ICEM棱柱网格生成方向【转载】

    转载自:http://blog.sina.com.cn/s/blog_8add9da60102v2hv.html 利用ICEM生成边界层网格(棱柱网格)时,发现生成的棱柱网格的方向不在流体域一侧,跑到 ...

  10. insomnihack CTF 2016-microwave

    目录 程序基本信息 程序漏洞 整体思路 exp脚本 内容参考 程序基本信息 程序防护全开,shellcode修改got表等方法都不太可行,同时pie开启也使程序代码随机化了. 程序漏洞 这是一个发推特 ...