【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 ...
随机推荐
- vue-resouce设置请求头
- mysql类型为varchar double类型字符串求和多出多个小数
-- 错误 SELECT SUM(price) FROM m_user -- 正确 SELECT TRUNCATE ( ) FROM m_user u; -- 正确 SELECT ) ) FROM m ...
- vue-cli 创建项目不成功 原因为项目文件夹无node_modules文件 进行npm install不成功解决办法
不知道有没有童鞋出现过全局安装vue-cli是成功的,但是创建项目时命令行报了很多错误,如下 本来是需要按照提示依次切换到项目文件夹,再npm run dev 即可完成项目创建并启动的,但是又报了如下 ...
- 前端面试题-JavaScript
引用GitHub 上 ltadpoles的前端面试 https://github.com/ltadpoles 目录 1. JavaScript 有哪些数据类型 2. 怎么判断不同的JS数据类型 ...
- Linux centOS 6 和 centOS 7一些简单的区别
最明显的是,获取网络端口的命令和IP信息的命令不同了 所以刚安装的centos 7 使用ifconfig查看ip时有可能出现-bash: ifconfig: 未找到命令
- jmeter md5加密请求参数
实际的接口测试过程中,再发生http之前有可能需要对某些参数(或某几个参数的组合)进行md5加密 在jmeter中可通过两种方式来实现md5加密 beanshell实现md5加密 在org.apach ...
- Greenplum 如何直连segment节点
Greenplum 展开阅读全文 直连greenplum segment节点的方法, utility模式 : 使用这种方式,不与其他节点通讯,只操作当前节点.也没有数据分布的概念. 如果使用uti ...
- TensorFlow(十七):训练自己的图片分类模型
(一)下载inception-v3--见TensorFlow(十四) (二)准备训练用的图片集,因为我没有图片集,所以写了个自动抓取百度图片的脚本-见抓取百度图片 (三)创建retrain.py文件, ...
- kvm 学习(三)存储池
创建kvm存储池 1.查看系统已经存储的存储池 [root@runstone ~ ::]#virsh pool-list Name State Autostart ------------------ ...
- ShardingSphere Hint模式 SpringBoot + Mybatis
ShardingSphere Hint模式不需要对sql进行解析,就可以进行数据库或者表的路由.下面贴一下代码,关于SpringBoot + Mybatis + ShardingSphere怎样结合. ...