class Solution {
public:
int getImportance(vector<Employee*> employees, int id) {
int importance = ;
map<int, Employee*> MAP;
for (auto em : employees)
{
MAP.insert(make_pair(em->id, em));
}
map<int, Employee*>::iterator iter;
iter = MAP.find(id);
queue<Employee*> Q;
if (iter != MAP.end())
{
int id = iter->first;
Employee* em = iter->second;
Q.push(em); while (!Q.empty())
{
Employee* emp = Q.front();
Q.pop();
importance += emp->importance;
for (auto subid : emp->subordinates)
{
map<int, Employee*>::iterator subiter;
subiter = MAP.find(subid);
if (subiter != MAP.end())
{
Q.push(subiter->second);
}
}
}
} return importance;
}
};

本题是分支限界法,广度优先搜索,使用map加速查询,防止超时。

leetcode690的更多相关文章

  1. [Java]LeetCode690. 员工的重要性 | Employee Importance

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

  2. Leetcode690.Employee Importance员工的重要性

    给定一个保存员工信息的数据结构,它包含了员工唯一的id,重要度 和 直系下属的id. 比如,员工1是员工2的领导,员工2是员工3的领导.他们相应的重要度为15, 10, 5.那么员工1的数据结构是[1 ...

  3. leetcode 78,236,300

    ---恢复内容开始--- 2018.3.16目前已刷27题,打卡记录有意思的题目. leetcode78 subsets 思路1:DFS遍历子集,每遇到一个数就把该数加上原来的子集变成新的子集. cl ...

随机推荐

  1. 22-THREE.JS 面材质

    <!DOCTYPE html> <html> <head> <title>Example 04.05 - Mesh face material</ ...

  2. mybatis 使用接口增删改查和两表一对一关联查询

    导包 总配置文件 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration ...

  3. hibernate13--缓存

    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN&q ...

  4. 剑指offer--24.树的子结构

    时间限制:1秒 空间限制:32768K 热度指数:407165 题目描述 输入两棵二叉树A,B,判断B是不是A的子结构.(ps:我们约定空树不是任意一个树的子结构)   class Solution ...

  5. L133

    The U.S. Food and Drug Administration is considering a ban on flavorede-cigarettes in response to an ...

  6. Activity Process Task Application 专题讲解

    Activity Process Task Application 专题讲解 Activity.和进程 为了阅读方便,将文档转成pdf http://files.cnblogs.com/franksu ...

  7. H5 pattern

    pattern:正则表达式验证 例如: <input pattern="1[3578]\d{9}">  可以省略^和$ 必须和required配合使用,否则在用户没有输 ...

  8. 旧书重温:0day2【4】动态获取函数地址

    通过以上3篇文章的学习,我们已经可以获取到kernel32.dll的地址了下一步 我们就是获取几个重要的函数 1.GetProcAddress 2.LoadLibrary 有了这两个函数很多函数都可以 ...

  9. php之opcodes

    opcode是一种php脚本编译之后的语言. 例如: <?php echo "Hello World"; $a = 1 + 1; echo $a; ?> php执行这段 ...

  10. 判定客户端IP所在的省市[2]

    在上一篇地址控件的基础上,添加了判定客户端IP所在省市的功能. 调用新浪提供的IP库接口:http://counter.sina.com.cn/ip/,(可直接点击链接查看返回的数据) 126提供的接 ...