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. springMvc--接受请求参数

    作者:liuconglin 接收基本类型 表单: <h1>接受基本类型参数到Controller</h1> <form action="/param/test& ...

  2. SublimeCodeIntel 所有代码提示和补全插件 All Autocomplete 插件搜索所有打开的文件来寻找匹配的提示词

    SublimeCodeIntelSublimeCodeIntel 作为一个代码提示和补全插件,支持 JavaScript.Mason.XBL.XUL.RHTML.SCSS.Python.HTML.Ru ...

  3. MySQL服务优化参数设置参考

    l 通用类: key_buffer_size 含义:用于索引块的缓冲区大小,增加它可得到更好处理的索引(对所有读和多重写). 影响:对于MyISAM表的影响不是很大,MyISAM会使用系统的缓存来存储 ...

  4. Neo4j 在Linux下的安装登录

    第一步:安装JDK https://blog.csdn.net/qq_33951308/article/details/82933535 第二步:下载并安装neo4j 下载地址   或者直接用wget ...

  5. cf242 E

    题意: $n$ 个数 $a_i$, 两种询问 $1, l, r$ 查询 $[l, r]$ 的和 $2, l, r, x$ 将区间 $[l, r]$ 所有数异或 $x$ 建立 $30$ 课线段树 第 $ ...

  6. TensorFlow(五):手写数字识别加强版

    # 该版本的最终识别准确率达到98%以上 import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_d ...

  7. CPU占用高系统反应慢之问题定位

    今天在看到公司群里有关于测试反应测试服务器比较卡,调用调用超时,响应很慢,成功率低的问题,然后想着去处理这个问题. 本着开发的精神,摒弃网管的水平,寻找问题的根源. 主要从如下几个方面入手: 1:查询 ...

  8. IIS Express(电脑无管理员权限如何启用VS调试)

    转载页面:https://www.cnblogs.com/xbblogs/p/4756552.html(详细版)  直接按照红色字体步骤执行,其他字体可先忽略 出问题再详细看   1.设置配置文件   ...

  9. [RK3399] Type-C改为MicroUSB

    CPU:RK3399 系统:Android 7.1.2 为了降低成本,主板将 Type-C 改为 MicroUSB 接口,节省了 fusb302芯片 参考 Rockchip 的官方文档第4部分:Mic ...

  10. final和finally的区别

    final关键字可以用于修饰类,方法,变量.用该关键字修饰类,方法,变量都有不可变的特性. 1)final关键字用于基本数据类型前,就表明该变量就变成了一个常量,在被定义后的赋值不能被修改. 2)fi ...