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

For example, employee 1 is the leader of employee 2, and employee 2 is the leader of employee 3. They have importance value 15, 10 and 5, respectively. Then employee 1 has a data structure like [1, 15, [2]], and employee 2 has [2, 10, [3]], and employee 3 has [3, 5, []]. Note that although employee 3 is also a subordinate of employee 1, the relationship is not direct.

Now given the employee information of a company, and an employee id, you need to return the total importance value of this employee and all his subordinates.

Example 1:

Input: [[1, 5, [2, 3]], [2, 3, []], [3, 3, []]], 1
Output: 11
Explanation:
Employee 1 has importance value 5, and he has two direct subordinates: employee 2 and employee 3. They both have importance value 3. So the total importance value of employee 1 is 5 + 3 + 3 = 11.

Note:

  1. One employee has at most one direct leader and may have several subordinates.
  2. The maximum number of employees won't exceed 2000.
class Solution
{
public int getImportance(List employees, int id)
{
int index = 0;
for(index = 0; index < employees.size(); index++)
{
if(employees.get(index).id == id)
break;
}
int result = employees.get(index).importance;
for(int i = 0; i < employees.get(index).subordinates.size(); i++)
{
result += getImportance(employees, employees.get(index).subordinates.get(i));
}
return result;
}
}

Depth-first Search-690. Employee Importance的更多相关文章

  1. (BFS) leetcode 690. Employee Importance

    690. Employee Importance Easy 377369FavoriteShare You are given a data structure of employee informa ...

  2. LN : leetcode 690 Employee Importance

    lc 690 Employee Importance 690 Employee Importance You are given a data structure of employee inform ...

  3. 【Leetcode_easy】690. Employee Importance

    problem 690. Employee Importance 题意:所有下属和自己的重要度之和,所有下属包括下属的下属即直接下属和间接下属. solution:DFS; /* // Employe ...

  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 ...

  10. leetcode 690. Employee Importance——本质上就是tree的DFS和BFS

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

随机推荐

  1. advance shading——菲涅耳现象

    (计算光照的时候,从两点出发考虑,光的传播方向,以及光的在这个方向上的能量.) 光与表面交互的模型包含两类:和物体表面(surface)以及和物体的内部(body).而subsurface指的是在物体 ...

  2. OSGi 系列(十八)之 基于注解的 Blueprint

    OSGi 系列(十八)之 基于注解的 Blueprint 1. 注解实现 blueprint 第一步:bundle 添加 Bundle-Blueprint-Annotation <plugin& ...

  3. mysql 1045 access denied for user********

    另一个方法Windows: 1. 管理员登陆系统,停止mysql服务或者结束mysqld-nt进程2. 进入命令行,来到mysql的安装目录.假设安装目录为 d:/mysql/ , CMD进入命令行3 ...

  4. 上海第八中学 shader

    http://shiba.hpe.cn/jiaoyanzu/wuli/soft/xna.aspx?classId=4

  5. how to enable the Accessibility in the app

    第一部分 先要装一个accchecker,全称是 UI Accessibility Checker .下载地址: http://acccheck.codeplex.com/ 装了之后 用这个工具可以 ...

  6. 【DBCP】DBCP基本配置和重连配置+spring中配置

    最近在看一些dbcp的相关内容,顺便做一下记录,免得自己给忘记了.   1. 引入dbcp (选择1.4) <dependency> <groupId>com.alibaba. ...

  7. 如何使用css来让图片居中不变形 微信小程序和web端适用

    图片变形很多人祭奠出了妖魔鬼怪般的各种大法,比如使用jq来写,或者使用css表达式来写.今天我总结的是使用css3来写,唯一最大缺点就是对一些浏览器版本不够兼容.下面就是关于如何使用css来让图片居中 ...

  8. android 蓝牙通讯编程 备忘

    1.启动App后: 判断->蓝牙是否打开(所有功能必须在打牙打开的情况下才能用) 已打开: 启动代码中的蓝牙通讯Service 未打开: 发布 打开蓝牙意图(系统),根据Activity返回进场 ...

  9. flask_hello world

    对于flask框架的学习全部借鉴于http://www.pythondoc.com/flask-mega-tutorial/index.html 在学习的过程中,我使用的是Pycharm IDE,Py ...

  10. SessionCacheTest03.testLoad Unrooted Tests initializationError

    这个错误主要是没有加载@Test这个标签,就是把其转化为一个juit测试的类.增加之后就没有问题了,当然还有很多人说是自己的Juit的版本问题,那就改下版本,还有说是没有加载两个类包,为了完整我就把包 ...