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. js事件冒泡/捕获

  2. vue1 监听数据变化

  3. 「数据结构与算法之链表(Python)」(四)

    什么是链表 顺序表的储存分为一体式结构和分离式结构,但总的来说存储数据的内存是一块连续的单元,每次申请前都要预估所需要的内存空间大小.这样就不能随意的增加我们需要的数据了.链接就是为了解决这个问题.它 ...

  4. 进程与线程与GIL的总结

  5. 01 - Element

    ¶安装 npm 安装 推荐使用 npm 的方式安装,它能更好地和 webpack 打包工具配合使用. npm i element-ui -S CDN 目前可以通过 unpkg.com/element- ...

  6. 最短路--Dijkstra

    Dijkstra--单源最短路 算法思想 主要记住这句话:每次选择没有被访问过的,并且dis最小的点,加入集合,更新dis 模板 int dis[maxn],vis[maxn]; //距离,标记 vo ...

  7. Excel开发VBA学习

    1.合并字符串A1&A22.拆分字符串LEFT(A2,SEARCH("-",A2)-1)3.下拉选项Data->Data validation->List 1. ...

  8. (5)打造简单OS-进入保护模式

    1.简介: 8086实模式 80286才出现保护模式,保护模式下的段寄存器存储的是段选择子,不在是8086实模式的段基址了! [扩展知识]:可以看了后面知识在回头看一下这段. [8086各个段寄存器和 ...

  9. SSH dao层异常 org.hibernate.HibernateException: No Session found for current thread

    解决方法: 在 接口方法中添加 事务注解 即可. public interface IBase<PK extends Serializable, T> { @Transactional v ...

  10. python3 系统监控脚本(CPU,memory,网络,disk等)

    #!/usr/bin/env python3 #create at 2018-11-30 'this is a system monitor scripts' __author__="yjt ...