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. Pthon操作Gitlab API----批量删除,创建,取消保护

    1.需求:大批量的应用上线后合并到Master,其他的分支develop/test/uat等需要同步最新代码的操作. 2.操作:可以通过传参 ,列表 的方式把每个项目的id值填入,才能对相关项目进行批 ...

  2. 基于FPGA自适应串口通信(Auto Baud Rate)

    做的课设,相当于复习了一遍verilog. 实现了 1.接收端固定模式:8N1 BAUD:921600. 2.发送端8N1,任意波特率(不取极端值). 3.数码管显示波特率(16进制). 用了 1.两 ...

  3. sudo 命令报 unable to resolve host 导致反应速度变慢

    1 分析 1.1 字面分析,不能解析主机 1.2 由于修改了本地主机名称所导致 2 解决 2.1 打开 /etc/hosts 2.2 主机名称指向,如你的主机名为 debian 2.3  127.0. ...

  4. learning scala Option[T]

    Option(选项)类型用来表示一个值是可选的(有值或无值). Option[T] 是一个类型为 T 的可选值的容器: 如果值存在, Option[T] 就是一个 Some[T] ,如果不存在, Op ...

  5. 一个简单的python实现百度登录操作

    conftest作为全局调用,用于登录之后的其他元素使用,且保持登录状态的操作 在开始前需要搭建好测试环境,环境包含python+webdriver+浏览器驱动(此处为firefox) 1.conft ...

  6. CentOS 7 常用命令大全(转)

    博主最近疯狂迷恋上linux的centos 7 系统,特意从网上找了一篇centos 7的命令大全来学习,下面我分享下这个博客. 转载自:https://blog.csdn.net/o0darknes ...

  7. Request模块入门学习

    使用指令npm install --save request来安装模块,然后使用var request = require('request')完成引用. 对于GET请求,主要是获取目的url中数据. ...

  8. Leetcode: Find First and Last Position of Element in Sorted Array

    Given a sorted array of integers, find the starting and ending position of a given target value. You ...

  9. ISO/IEC 9899:2011 条款6.2.8——对象的对齐

    6.2.8 对象的对齐 1.完整的对象类型具有对齐要求,对齐要求是对该类型对象可以在哪个地址进行分配的放置限制.一个对齐是一个实现定义的整数值,表示一个给定对象可以分配在相继两个地址之间跨多少字节的位 ...

  10. OS X环境下如何搭建编译Cocos2D-X v3.x的Android Studio工程

    Cocos2D-X官网已经简单介绍了如何在OS X环境下搭建Cocos2D-X v2.x和v3.x的指南.具体链接为:http://www.cocos.com/doc/article/index?ty ...